Sum of primes in odd positions is prime: Difference between revisions

→‎{{header|ALGOL 68}}: Use the new prime list routines in Algol 68-primes
(Added Algol 68)
(→‎{{header|ALGOL 68}}: Use the new prime list routines in Algol 68-primes)
Line 12:
{{libheader|ALGOL 68-primes}}
<lang algol68>BEGIN # find primes (up to 999) p(i) for odd i such that the sum of primes p(j), j = 1, 3, 5, ..., i is prime #
INT max prime = 999;
PR read "primes.incl.a68" PR
INT max prime = 999;
[]BOOL prime = PRIMESIEVE 50 000; # guess that the max sum will be <= 50 000 #
# count the primes up to max prime #
[]INT p countlow prime := 0;EXTRACTPRIMESUPTO FORmax iprime TO maxFROMPRIMESIEVE prime; DO# IFget prime[a ilist ]of THENprimes pup countto +:=max 1prime FI OD; #
# construct a list of the primes up to max prime #
[ 1 : p count ]INT low prime;
INT low pos := 0;
FOR i TO max prime DO IF prime[ i ] THEN low prime[ low pos +:= 1 ] := i FI OD;
# find the sums of the odd primes and test for primality #
print( ( " i p[i] sum", newline ) );
3,045

edits