Additive primes: Difference between revisions
Content deleted Content added
→{{header|ALGOL 68}}: Use ALGOL 68-primes |
|||
Line 19: | Line 19: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
{{libheader|ALGOL 68-primes}} |
|||
<lang algol68>BEGIN # find additive primes - primes whose digit sum is also prime # |
<lang algol68>BEGIN # find additive primes - primes whose digit sum is also prime # |
||
INT max prime = 499; |
|||
# sieve the primes to max prime # |
# sieve the primes to max prime # |
||
PR read "primes.incl.a68" PR |
|||
[ 1 : max prime ]BOOL prime; |
|||
[]BOOL prime = PRIMESIEVE 499; |
|||
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 additive primes # |
# find the additive primes # |
||
INT additive count := 0; |
INT additive count := 0; |
||
FOR n TO |
FOR n TO UPB prime DO |
||
IF prime[ n ] THEN |
IF prime[ n ] THEN |
||
# have a prime # |
# have a prime # |
||
Line 47: | Line 42: | ||
FI |
FI |
||
OD; |
OD; |
||
print( ( newline, "Found ", whole( additive count, 0 ), " additive primes below ", whole( |
print( ( newline, "Found ", whole( additive count, 0 ), " additive primes below ", whole( UPB prime + 1, 0 ), newline ) ) |
||
END</lang> |
END</lang> |
||
{{out}} |
{{out}} |