请高手进来看看为什么会超时

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 条评论

  • @ 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

信息

ID
1042
难度
7
分类
搜索 | 搜索与剪枝 点击显示
标签
(无)
递交数
6601
已通过
1521
通过率
23%
被复制
13
上传者