Cuban primes: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: Minor tidy)
Line 33:
 
=={{header|ALGOL 68}}==
<syntaxhighlight lang="algol68">BEGIN
BEGIN
# find some cuban primes (using the definition: a prime p is a cuban prime if #
# p = n^3 - ( n - 1 )^3 #
Line 68 ⟶ 69:
# construct a list of the primes #
[ 1 : prime count ]INT primes;
INT prime pos := LWB primes - 1;
FOR s FROM LWB sieve TO UPB sieve DO
IF sieve[ s ] THEN primes[ prime pos ] +:= s;1 prime] pos +:= 1s FI
OD;
 
Line 86 ⟶ 87:
IF ODD p THEN
# 2 is not a cuban prime so we only test odd numbers #
BOOL is prime := TRUE;
INT max factor IF p <= SHORTENUPB ENTIER long sqrt( psieve );THEN
FOR f FROM LWB primes WHILE is prime AND:= primessieve[ fSHORTEN p ] <= max factor DO
is prime := p MOD primes[ f ] /= 0ELSE
INT max factor = SHORTEN ENTIER long sqrt( p );
OD;
FOR f FROM LWB primes WHILE is prime AND primes[ f ] <= max factor DO
is prime := p MOD primes[ f ] /= 0
OD
ODFI;
IF is prime THEN
# have a cuban prime #
IF ( cuban count +:= 1; ) <= print limit THEN
IF cuban count <= print limit THEN
# must show this cuban #
STRING p formatted = commatise( p );
Line 107 ⟶ 111:
IF cuban count MOD 10 /= 0 THEN print( ( newline ) ) FI;
print( ( "The ", commatise( max cuban ), " cuban prime is: ", commatise( final cuban ), newline ) )
END
END</syntaxhighlight>
{{out}}
<pre>