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}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
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 #
# foe some factorial f #
 
PR read "primes.incl.a68" PR # include prime utilities including #
# is probably 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:
print( ( whole( fp number, -2 ), ":", whole( n, -4 )
Line 44 ⟶ 52:
f *:= n;
IF LONG INT fp = f - 1;
is probably prime( fp )
THEN
fp count +:= 1;
Line 50 ⟶ 58:
FI;
IF LONG INT fp = f + 1;
is probably prime( fpf + 1 )
THEN
fp count +:= 1;
3,048

edits