Summarize primes: Difference between revisions
Content added Content deleted
(→{{header|jq}}: tidy) |
(→{{header|ALGOL 68}}: Use ALGOL 68-primes) |
||
Line 10: | Line 10: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
{{libheader|ALGOL 68-primes}} |
|||
<lang algol68>BEGIN # sum the primes below n and report the sums that are prime # |
<lang algol68>BEGIN # sum the primes below n and report the sums that are prime # |
||
# sieve the primes to 999 # |
|||
INT max prime = 999; # largest prime to consider # |
|||
PR read "primes.incl.a68" PR |
|||
[ |
[]BOOL prime = PRIMESIEVE 999; |
||
prime[ 1 ] := FALSE; prime[ 2 ] := TRUE; |
|||
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; |
|||
# sum the primes and test the sum # |
# sum the primes and test the sum # |
||
INT prime sum := 0; |
INT prime sum := 0; |
||
Line 26: | Line 21: | ||
print( ( "prime prime", newline ) ); |
print( ( "prime prime", newline ) ); |
||
print( ( "count prime sum", newline ) ); |
print( ( "count prime sum", newline ) ); |
||
FOR i TO |
FOR i TO UPB prime DO |
||
IF prime[ i ] THEN |
IF prime[ i ] THEN |
||
# have another prime # |
# have another prime # |
||
Line 54: | Line 49: | ||
, whole( prime sum count, 0 ) |
, whole( prime sum count, 0 ) |
||
, " prime sums of primes below " |
, " prime sums of primes below " |
||
, whole( |
, whole( UPB prime + 1, 0 ) |
||
, newline |
, newline |
||
) |
) |
||
) |
) |
||
END |
END</lang> |
||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |