- 捕风捉影
- 2009-09-12 08:24:05 @
var
j,n,m:longint;
function sushu(x:longint):boolean;
var
i,k:longint;
begin
sushu:=true;
for i:=2 to trunc(sqrt(x)) do
begin
k:=x mod i;
if k=0 then
begin
sushu:=false;
break;
end;
end;
end;
function huiwen(x:longint):boolean;
var
s:string;
len,b,c,i:longint;
a:array[1..100000] of integer;
begin
str(x,s);
len:=length(s);
for i:=1 to len do
begin
a[i]:=x mod 10;
x:=x div 10;
end;
b:=1;
c:=len;
while b=c then huiwen:=true;
end;
begin
readln(m,n);
for j:=m to n do
if huiwen(j) and sushu(j) then writeln(j);
end.
1 条评论
-
nr_give_up LV 8 @ 2009-09-12 15:20:50
修改后的程序还是超时的
var
j,n,m:longint;function sushu(x:longint):boolean;
var
i,k:longint;
begin
sushu:=true;
for i:=2 to trunc(sqrt(x)) do
begin
k:=x mod i;
if k=0 then
begin
sushu:=false;
break;
end;
end;
end;function huiwen(x:longint):boolean;
var
s:string;
len,b,c:longint;
a:array[1..100000] of integer;
begin
if x>9989899 then exit(false)
else
str(x,s);
len:=length(s);
b:=1; c:=len;
while bc then exit(true);
end;begin
readln(m,n);
for j:=m to n do
if sushu(j) and huiwen(j) then writeln(j);
end.
- 1