Euclid-Mullin sequence: Difference between revisions

Content added Content deleted
(Upgraded to 'full' task.)
(Added Algol 68)
Line 17: Line 17:
[https://oeis.org/A000945 OEIS sequence A000945]
[https://oeis.org/A000945 OEIS sequence A000945]
<br><br>
<br><br>

=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
Uses ALGOL 68G's LONG LONG INT which has programmer specifiable precission, the default is sufficient for this task.
<br>
Although the first 16 elements will all fit in 64 bits, the product exceeds 64 bits after the ninth element.
<syntaxhighlight lang="algol68">
BEGIN # find elements of the Euclid-Mullin sequence: starting from 2, #
# the next element is the smallest prime factor of 1 + the product #
# of the previous elements #
print( ( " 2" ) );
LONG LONG INT product := 2;
FROM 2 TO 16 DO
LONG LONG INT next := product + 1;
# find the first prime factor of next #
LONG LONG INT p := 3;
BOOL found := FALSE;
WHILE p * p <= next AND NOT ( found := next MOD p = 0 ) DO
p +:= 2
OD;
IF found THEN next := p FI;
print( ( " ", whole( next, 0 ) ) );
product *:= next
OD
END
</syntaxhighlight>
{{out}}
<pre>
2 3 7 43 13 53 5 6221671 38709183810571 139 2801 11 17 5471 52662739 23003
</pre>


=={{header|AWK}}==
=={{header|AWK}}==
Line 50: Line 80:
2 3 7 43 13 53 5 6221671
2 3 7 43 13 53 5 6221671
</pre>
</pre>

=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
<syntaxhighlight lang="fsharp">