Nice primes: Difference between revisions

Content added Content deleted
(Added Fōrmulæ solution)
(→‎{{header|ALGOL 68}}: Use Algol 68-primes)
Line 27: Line 27:


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-primes}}
<lang algol68>BEGIN # find nice primes - primes whose digital root is also prime #
<lang algol68>BEGIN # find nice primes - primes whose digital root is also prime #
INT min prime = 501;
INT min prime = 501;
INT max prime = 999;
INT max prime = 999;
# sieve the primes to max prime #
# sieve the primes to max prime #
PR read "primes.incl.a68" PR
[ 1 : max prime ]BOOL prime;
prime[ 1 ] := FALSE; prime[ 2 ] := TRUE;
[]BOOL prime = PRIMESIEVE max prime;
FOR i FROM 3 BY 2 TO UPB prime DO prime[ i ] := TRUE OD;
FOR i FROM 4 BY 2 TO UPB prime DO prime[ i ] := FALSE OD;
FOR i FROM 3 BY 2 TO ENTIER sqrt( max prime ) DO
IF prime[ i ] THEN FOR s FROM i * i BY i + i TO UPB prime DO prime[ s ] := FALSE OD FI
OD;
# find the nice primes #
# find the nice primes #
INT nice count := 0;
INT nice count := 0;