Least m such that n! + m is prime: Difference between revisions

Added Algol 68
m (Minor bug fix in the task description)
(Added Algol 68)
Line 27:
 
 
 
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-primes}}
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
Uses ALGOL 68G's LONG LONG INT which has programmer specifiable precision, 500 digits is sufficient for the basic task (the Millar Rabin routine needs extra digits, even though 107! has around 170 digits).
<syntaxhighlight lang="algol68">
BEGIN # find the least m such that n! + m is prime for various n #
PR precision 500 PR # set the precision of LONG LOMG INT #
PR read "primes.incl.a68" PR # include priee utilities #
LONG LONG INT factorial n := 1;
INT m := 0;
FOR n FROM 0 WHILE m < 1000 DO
IF n > 0 THEN
factorial n *:= n
FI;
m := 1;
WHILE NOT is probably prime( factorial n + m ) DO
m +:= 2
OD;
IF n < 50 THEN
print( ( " ", whole( m, -4 ) ) );
IF ( n + 1 ) MOD 10 = 0 THEN print( ( newline ) ) FI
ELIF m > 1000 THEN
print( ( "First m > 1000: ", whole( m, 0 ), " for ", whole( n, 0 ), "!", newline ) )
FI
OD
END
</syntaxhighlight>
{{out}}
<pre>
1 1 1 1 5 7 7 11 23 17
11 1 29 67 19 43 23 31 37 89
29 31 31 97 131 41 59 1 67 223
107 127 79 37 97 61 131 1 43 97
53 1 97 71 47 239 101 233 53 83
First m > 1000: 1069 for 107!
</pre>
 
=={{header|C}}==
3,048

edits