Cuban primes: Difference between revisions
→{{header|ALGOL 68}}: Use Miller Rabin for primality tesing
(→{{header|ALGOL 68}}: Tweaks) |
(→{{header|ALGOL 68}}: Use Miller Rabin for primality tesing) |
||
Line 38:
# p = n^3 - ( n - 1 )^3 #
# for some n > 0) #
PR read "primes.incl.a68" PR # include prime utilities #
# returns a string representation of n with commas #
PROC commatise = ( LONG INT n )STRING:
Line 54:
END # commatise # ;
INT sieve max = 2 000 000;
[]BOOL sieve
# find the cuban primes #
Line 79 ⟶ 62:
INT max cuban = 100 000; # mximum number of cubans to find #
INT print limit = 200; # show all cubans up to this one #
print( ( "First ", commatise( print limit ), " cuban primes:
LONG INT prev cube := 1;
FOR n FROM 2 WHILE
Line 87 ⟶ 70:
IF ODD p THEN
# 2 is not a cuban prime so we only test odd numbers #
# have a cuban prime #
IF ( cuban count +:= 1 ) <= print limit THEN
Line 115 ⟶ 90:
{{out}}
<pre>
First 200 cuban primes:
7 19 37 61 127 271 331 397 547 631
919 1,657 1,801 1,951 2,269 2,437 2,791 3,169 3,571 4,219
|