Smallest number k such that k+2^m is composite for all m less than k: Difference between revisions

Added Algol 68
(Added Algol 68)
 
Line 25:
 
[[oeis:A033919|OEIS:A033919 - Odd k for which k+2^m is composite for all m < k]]
 
=={{header|ALGOL 68}}==
{{Trans|Java|but basically the same brute-force algorithm used by most other samples}}
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
Uses Algol 68G's LONG LONG INT which has programmer specifiable precision.<br>
This will take some time...
{{libheader|ALGOL 68-primes}}
The source of primes.incl.a68 is on another page on Rosetta Code - see the above link.
<syntaxhighlight lang="algol68">
BEGIN # find the smallest k such that k+2^m is composite for all 0 < m < k #
# this is sequence A033919 on the OEIS #
PR precision 5000 PR # set the precision of LONG LONG INT #
PR read "primes.incl.a68" PR # include prime utilities #
 
PROC is a033919 = ( INT ak )BOOL:
BEGIN
LONG LONG INT big k = ak;
LONG LONG INT p2 := 2;
BOOL result := FALSE;
FOR m TO ak - 1 WHILE result := NOT is probably prime( big k + p2 ) DO p2 *:= 2 OD;
result
END # is a033919 # ;
 
INT count := 0;
FOR k FROM 3 BY 2 WHILE count < 5 DO
IF is a033919( k ) THEN
print( ( whole( k, 0 ), " " ) );
count +:= 1
FI
OD;
print( ( newline ) )
 
END</syntaxhighlight>
{{out}}
<pre>
773 2131 2491 4471 5101
</pre>
 
=={{header|FreeBASIC}}==
3,038

edits