a007.
判斷質數
| From: [183.179.64.148] |
發表日期
:
2015-04-10 16:16
在dev-pascal 和在測試執行中也沒事,順利通過,但為何在過測資點的時候就RE了呢?
求高人解答
他要是OLE我還可以繼續改,他是RE我又找不到bug我就卡住了......
var
prime : array[1..5000] of integer;
input : longint;
node : word;
i,j : word;
bound : double;
boundi : integer;
nodeMove, isPrime : boolean;
begin
//init
prime[1]:=2;
prime[2]:=3;
node:=2;
repeat
nodeMove:=false;
i:=prime[node]+2;
bound:=sqrt(i);
boundi:=trunc(bound);
repeat
isPrime:=true;
j:=2;
while (isPrime=true) and (j<=node) and (prime[j]<boundi) do
begin
if i mod prime[j]=0 then isPrime:=false;
inc(j);
end;
if isPrime=true
then begin
inc(node);
prime[node]:=i;
nodeMove:=true;
end
else begin
i:=i+2;
bound:=sqrt(i);
boundi:=trunc(bound);
end;
until (nodeMove=true);
until node=4792;
prime[4793]:=999999;
//main
while not(eof) do
begin
readln(input);
bound:=sqrt(input);
boundi:=trunc(bound);
i:=1;
isPrime:=true;
while (prime[i]<boundi) and (isPrime=true) do
begin
if (input mod prime[i] = 0) then isPrime:=false;
inc(i);
end;
if isPrime=true then writeln('質數')
else writeln('非質數');
end;
end.