素数 "列挙" アルゴリズムを極めるスレ
■ このスレッドは過去ログ倉庫に格納されています
0313デフォルトの名無しさん
NGNGn:=5;
while n< SQRTMAX do begin
if not Bits[n div 3] then begin
writeln(n,' ',GetTickCount-t0);
x:=(n*n) div 3;
n2:=2*n;
n1:=(n div 6)*4+3;
while x<MAX3 do begin Bits[x]:=True;Bits[x+n1]:=True;inc(x,n2);end;
end;
inc(n,2);
if not Bits[n div 3] then begin
writeln(n,' ',GetTickCount-t0);
x:=(n*n) div 3;
n2:=2*n;
n1:=(n div 6)*8+1;
while x<MAX3 do begin Bits[x]:=True;Bits[x+n1]:=True;inc(x,n2);end;
end;
inc(n,4);
end;
コード中の while x<MAX の停止条件が甘いので、BitsのSizeは(MAX+SQRTMAX)/3にしておいた方がいいです
■ このスレッドは過去ログ倉庫に格納されています