var
a:array[0..10,1..1000000] of boolean;
b,c,d,e,i,j,s,z:longint;
begin
s:=0;
z:=1;
for e:=2 to 1073741823 do begin
i:=e*2-1;
for j:=2 to trunc(sqrt(i)) do begin
z:=i;
while i>1000000 do begin
z:=i-1000000;
s:=s+1;
end;
a[s,z]:=true;
if i mod j=0 then begin a[s,z]:=false; break; end;
end;
end;
while not eof do begin
readln(b);
d:=0;
while b>1000000 do begin
c:=b-1000000;
d:=d+1;
end;
if b=1 then writeln('非質數')
else if b=2 then writeln('質數')
else if a[d,c]=true then writeln('質數')
else writeln('非質數');
readln(b);
end;
end.
这是我的代码,请帮忙看看
我用費馬小定理過的,很麻煩
我想有機會貼一下文章