Special neighbor primes: Difference between revisions

→‎{{header|ALGOL 68}}: Use the new prime list routines in Algol 68-primes
(→‎{{header|ALGOL 68}}: Use the new prime list routines in Algol 68-primes)
Line 10:
{{libheader|ALGOL 68-primes}}
<lang algol68>BEGIN # find adjacent primes p1, p2 such that p1 + p2 - 1 is also prime #
INT max prime = 100;
# sieve the primes to max prime * 2 #
PR read "primes.incl.a68" PR
[]BOOL prime = PRIMESIEVE (INT max prime * 2= )100;
[]BOOL prime = PRIMESIEVE ( max prime * 2 ); # countsieve the primes up to max prime * 2 #
[]INT plow countprime := 0;EXTRACTPRIMESUPTO FORmax iprime TO maxFROMPRIMESIEVE prime; DO IF# prime[construct ia ]list THENof pthe countprimes +:=up 1to FImax OD;prime #
# construct a list of the primes up to max prime #
[ 1 : p count ]INT low prime;
INT low pos := 0;
FOR i WHILE low pos < UPB low prime DO IF prime[ i ] THEN low prime[ low pos +:= 1 ] := i FI OD;
# find the adjacent primes p1, p2 such that p1 + p2 - 1 is prime #
FOR i TO UPB low prime - 1 DO
3,032

edits