|
|
DataMuseum.dkPresents historical artifacts from the history of: Bogika Butler |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Bogika Butler Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 2432 (0x980)
Types: TextFile
Names: »PRIMES.PRN«
└─⟦314366c8f⟧ Bits:30009789/_.ft.Ibm2.50006598.imd Mogens Pelles Zilog 80,000 / EOS projekt
└─⟦this⟧ »PRIMES.PRN«
Pro Pascal Compiler - Version zz 2.1
Compilation of: primes.PAS
Options: LNIAPG
1 0000 PROGRAM primes(input,output);
2 0000 æComputes primes up to a given limit,
3 0000 using the "sieve of Eratosthenes" å
4 0000 CONST
5 0000 maxnumber = 32767;
6 0000 maxhalf = 16383; æmaxnumber DIV 2å
7 0000 TYPE
8 0000 number = 1..maxnumber;
9 0000 half = 1..maxhalf;
10 0000 VAR
11 0000 count,factor,maxfactor,limit,nonprime: number;
12 0000 index,halflimit: half;
13 0000 primeflags: ARRAY ÆhalfÅ OF boolean;
14 0000 BEGIN
15 0000 REPEAT
16 000E writeln('Upper limit = ?');
17 0035 readln(limit);
18 004C UNTIL (1 <= limit) AND (limit <= maxnumber);
19 0072 halflimit := pred(limit) DIV 2;
20 0097 FOR index := 1 TO halflimit DO primeflagsÆindexÅ := true;
21 00CB æIf a number is composite, at least one of its factors is
22 00CB less than or equal to its square root, so: å
23 00CB maxfactor := round(sqrt(limit));
24 00EF count := 2; æcount of primes: 1 and 2 are the first twoå
25 00FA factor := 1; æfirst actual factor used will be 3å
26 0105 FOR index := 1 TO halflimit DO
27 0123 BEGIN
28 0128 factor := factor + 2; æi.e. factor := 2*index + 1å
29 014A IF primeflagsÆindexÅ THEN
30 015E æA new prime has been found å
31 015E BEGIN count := succ(count);
32 0178 æIf necessary, cross out all its multipleså
33 0178 IF factor <= maxfactor THEN
34 018D BEGIN nonprime := index + factor;
35 01B2 WHILE nonprime <= halflimit DO
36 01C7 BEGIN
37 01CC primeflagsÆnonprimeÅ := false;
38 01DD nonprime := nonprime + factor;
39 0202 END æWHILEå;
40 0205 END;
41 0205 writeln(factor); æomitted for timingå
42 0221 END æIFå;
43 0221 END æFORå;
44 022F writeln('Number of primes up to ',limit,' = ',count);
45 0290 END.
«eof»