Sum of two adjacent numbers are primes: Difference between revisions
Sum of two adjacent numbers are primes (view source)
Revision as of 14:54, 18 December 2022
, 1 year ago→{{header|ALGOL 68}}: Simplify as per the Phix sample
(→ "Show on this page the first 20 prime sums of two consecutive integers") |
(→{{header|ALGOL 68}}: Simplify as per the Phix sample) |
||
Line 61:
=={{header|ALGOL 68}}==
Using Pete Lomax's observation that all odd primes are n + n+1 for some n - see [[#Phix]]
{{libheader|ALGOL 68-primes}}
<syntaxhighlight lang="algol68">BEGIN # find the first 20 primes which are n + ( n + 1 ) for some n #
Line 66 ⟶ 67:
[]BOOL prime = PRIMESIEVE 200; # should be enough primes #
INT p count := 0;
FOR
INT n1 = n + 1;▼
INT p = n + n1;▼
IF prime[ p ] THEN
▲ INT n1 = n + 1;
p count +:= 1;
print( ( whole( n, -2 ), " + ", whole( n1, -2 ), " = ", whole( p, -3 ), newline ) )
FI
OD
END
{{out}}
<pre>
|