mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-29 08:43:07 +02:00
uses pointer instead of dynamic array which needs initialization.
git-svn-id: trunk@5552 -
This commit is contained in:
parent
9a90410081
commit
0a983cfa11
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user