Factorial primes: Difference between revisions
→{{header|ALGOL 68}}: Use trial division to test for primes as we are only going up to the tenth factorial prime
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:
<br><br>
=={{header|ALGOL 68}}==
Basic task. Assumes LONG INT is at least 64 bits.
<lang algol68>BEGIN # find some factorial primes - primes that are f - 1 or f + 1 #
# foe some factorial f #
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:
print( ( whole( fp number, -2 ), ":", whole( n, -4 )
Line 44 ⟶ 52:
f *:= n;
IF LONG INT fp = f - 1;
is
THEN
fp count +:= 1;
Line 50 ⟶ 58:
FI;
IF LONG INT fp = f + 1;
is
THEN
fp count +:= 1;
|