uses pointer instead of dynamic array which needs initialization.

git-svn-id: trunk@5552 -
This commit is contained in:
Vincent Snijders 2006-12-07 13:38:33 +00:00
parent 9a90410081
commit 0a983cfa11

View File

@ -6,31 +6,32 @@
program nsieve; program nsieve;
{$mode objfpc} {$mode objfpc}{$I-}
var n : integer; var
n : integer;
procedure primes(n : integer); inline; procedure primes(n : integer); inline;
var flags : array of boolean; var
flags: PBoolean;
size,i,j,count : integer; size,i,j,count : integer;
begin begin
size := 10000 shl n; size := 10000 shl n;
SetLength(flags, size+1); flags := getmem(size+1);
for i := 2 to size do flags[i] := true; fillchar(flags^,memsize(flags),true);
//fillchar(flags[0],length(flags),ord(true));
count := 0; count := 0;
for i := 2 to size do for i := 2 to size do
if flags[i] then if flags[i] then
begin begin
count := count + 1; inc(count);
j := i + i; j := i + i;
while j <= size do begin while j <= size do begin
// flags[j] := false; flags[j] := false;
if flags[j] then flags[j] := false; inc(j, i);
j := j + i;
end; end;
end; end;
writeln('Primes up to', size:9, count:9); writeln('Primes up to', size:9, count:9);
freemem(flags);
end; end;
begin begin