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

Content added Content deleted
(Created Nim solution.)
(New post.)
Line 69: Line 69:


{{out}}
{{out}}
<pre>
773 2131 2491 4471 5101
</pre>

=={{header|Java}}==
<syntaxhighlight lang="java">

import java.math.BigInteger;

public final class SmallestNumberK {

public static void main(String[] aArgs) {
int count = 0;
int k = 3;
while ( count < 5 ) {
if ( isValid(k) ) {
System.out.print(k + " ");
count += 1;
}
k += 2;
}
System.out.println();
}
private static boolean isValid(int aK) {
final BigInteger bigK = BigInteger.valueOf(aK);
for ( int m = 1; m < aK; m++ ) {
if ( bigK.add(BigInteger.ONE.shiftLeft(m)).isProbablePrime(20) ) {
return false;
}
}
return true;
}

}
</syntaxhighlight>
{{ out }}
<pre>
<pre>
773 2131 2491 4471 5101
773 2131 2491 4471 5101