Cubic special primes: Difference between revisions

Added Algol 68
(added AWK)
(Added Algol 68)
Line 6:
where     '''n'''   <   '''15000'''.
<br><br>
 
=={{header|ALGOL 68}}==
<lang algol68>BEGIN # find a sequence of primes where the members differ by a cube #
INT max prime = 15 000;
# sieve the primes to max prime #
[ 1 : max prime ]BOOL prime;
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;
# construct a table of cubes, we will need at most the cube root of max prime #
[ 1 : ENTIER exp( ln( max prime ) / 3 ) ]INT cube;
FOR i TO UPB cube DO cube[ i ] := i * i * i OD;
# find the prime sequence #
print( ( "2" ) );
INT p := 2;
WHILE p < max prime DO
# find a prime that is p + a cube #
INT q := 0;
FOR i WHILE q := p + cube[ i ];
IF q > max prime THEN FALSE ELSE NOT prime[ q ] FI
DO SKIP OD;
IF q <= max prime THEN print( ( " ", whole( q, 0 ) ) ) FI;
p := q
OD;
print( ( newline ) )
END</lang>
{{out}}
<pre>
2 3 11 19 83 1811 2027 2243 2251 2467 2531 2539 3539 3547 4547 5059 10891 12619 13619 13627 13691 13907 14419
</pre>
 
=={{header|AWK}}==
Line 49 ⟶ 82:
Cubic special primes 2-15000: 23
</pre>
 
=={{header|F_Sharp|F#}}==
<lang fsharp>
3,043

edits