Factorial primes: Difference between revisions
Content added Content deleted
m (→{{header|ALGOL 68}}: (very) small tweak) |
(→{{header|ALGOL 68}}: Use trial division to test for primes as we are only going up to the tenth factorial prime) |
||
Line 26: | Line 26: | ||
<br><br> |
<br><br> |
||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}} |
|||
Basic task. Assumes LONG INT is at least 64 bits. |
Basic task. Assumes LONG INT is at least 64 bits. |
||
{{libheader|ALGOL 68-primes}} (NB: the library source is on rosettacode). |
|||
<lang algol68>BEGIN # find some factorial primes - primes that are f - 1 or f + 1 # |
<lang algol68>BEGIN # find some factorial primes - primes that are f - 1 or f + 1 # |
||
# foe some factorial f # |
# foe some factorial f # |
||
PR read "primes.incl.a68" PR # include prime utilities including # |
|||
# is prime PROC based on the one in the primality by trial division task # |
|||
PROC is prime = ( LONG INT p )BOOL: |
|||
IF p <= 1 OR NOT ODD p THEN |
|||
p = 2 |
|||
ELSE |
|||
BOOL prime := TRUE; |
|||
FOR i FROM 3 BY 2 TO SHORTEN ENTIER long sqrt(p) WHILE prime := p MOD i /= 0 DO SKIP OD; |
|||
prime |
|||
FI; |
|||
# end of code from the primality by trial divisio task # |
|||
PROC show factorial prime = ( INT fp number, INT n, CHAR fp op, LONG INT fp )VOID: |
PROC show factorial prime = ( INT fp number, INT n, CHAR fp op, LONG INT fp )VOID: |
||
print( ( whole( fp number, -2 ), ":", whole( n, -4 ) |
print( ( whole( fp number, -2 ), ":", whole( n, -4 ) |
||
Line 44: | Line 52: | ||
f *:= n; |
f *:= n; |
||
IF LONG INT fp = f - 1; |
IF LONG INT fp = f - 1; |
||
is |
is prime( fp ) |
||
THEN |
THEN |
||
fp count +:= 1; |
fp count +:= 1; |
||
Line 50: | Line 58: | ||
FI; |
FI; |
||
IF LONG INT fp = f + 1; |
IF LONG INT fp = f + 1; |
||
is |
is prime( f + 1 ) |
||
THEN |
THEN |
||
fp count +:= 1; |
fp count +:= 1; |