Cuban primes: Difference between revisions
→{{header|ALGOL 68}}: Tweaks
m (→{{header|Wren}}: Minor tidy) |
(→{{header|ALGOL 68}}: Tweaks) |
||
Line 33:
=={{header|ALGOL 68}}==
<syntaxhighlight lang="algol68">
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
OD;
Line 86 ⟶ 87:
IF ODD p THEN
# 2 is not a cuban prime so we only test odd numbers #
BOOL is prime
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
IF is prime THEN
# have a cuban prime #
IF ( cuban count +:= 1
# 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
{{out}}
<pre>
|