-
Notifications
You must be signed in to change notification settings - Fork 9
/
genprime.dpr
76 lines (72 loc) · 1.96 KB
/
genprime.dpr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
program GenPrime;
uses
SysUtils;
const
PrimeLimit = 9999;
var
Primes : array [1..PrimeLimit] of boolean;
i, j, Count, PrimeCount, MaxPrime : integer;
NewLine : boolean;
F : text;
begin
FillChar(Primes, sizeof(Primes), 1);
Primes[1] := false;
for i := 2 to PrimeLimit do begin
if Primes[i] then begin
j := i+i;
while j <= PrimeLimit do begin
Primes[j] := false;
inc(j, i);
end;
end;
end;
PrimeCount := 0;
for i := 1 to PrimeLimit do
if Primes[i] then
inc(PrimeCount);
assign(F, 'EZPrimes.Inc');
rewrite(F);
writeln(F, '{*********************************************************}');
writeln(F, '{* EZPrimes.INC *}');
writeln(F, '{* Copyright (c) Julian M Bucknall 1997-2015 *}');
writeln(F, '{* All rights reserved. *}');
writeln(F, '{* Version: 3.10 *}');
writeln(F, '{*********************************************************}');
writeln(F, '{* Prime number array include file (auto-generated) *}');
writeln(F, '{*********************************************************}');
writeln(F);
writeln(F, 'const');
writeln(F, ' PrimeCount = ', PrimeCount, ';');
writeln(F, 'const');
writeln(F, ' Primes : array [0..pred(PrimeCount)] of word = (');
NewLine := true;
j := 0;
Count := 0;
for i := 1 to PrimeLimit do begin
if NewLine then begin
write(F, ' ');
NewLine := false;
end;
if Primes[i] then begin
inc(Count);
if (Count = PrimeCount) then begin
write(F, i:4);
MaxPrime := i;
end
else
write(F, i:4, ', ');
inc(j);
if (j = 10) then begin
writeln(F);
j := 0;
NewLine := true;
end;
end;
end;
if not NewLine then
writeln(F);
writeln(F, ' );');
writeln(F, 'const');
writeln(F, ' MaxPrime = ', MaxPrime, ';');
close(F);
end.