Repunit primes: Difference between revisions
Content added Content deleted
(Created Nim solution.) |
(New post.) |
||
Line 304: | Line 304: | ||
Base 35: [313 1297] |
Base 35: [313 1297] |
||
Base 36: [2] |
Base 36: [2] |
||
</pre> |
|||
=={{header|Java}}== |
|||
<syntaxhighlight lang="java"> |
|||
import java.math.BigInteger; |
|||
public final class RepunitPrimes { |
|||
public static void main(String[] aArgs) { |
|||
final int limit = 2_700; |
|||
System.out.println("Repunit primes, up to " + limit + " digits, in:"); |
|||
for ( int base = 2; base <= 16; base++ ) { |
|||
System.out.print(String.format("%s%2s%s", "Base ", base, ": ")); |
|||
String repunit = ""; |
|||
while ( repunit.length() < limit ) { |
|||
repunit += "1"; |
|||
if ( BigInteger.valueOf(repunit.length()).isProbablePrime(CERTAINTY_LEVEL) ) { |
|||
BigInteger value = new BigInteger(repunit, base); |
|||
if ( value.isProbablePrime(CERTAINTY_LEVEL) ) { |
|||
System.out.print(repunit.length() + " "); |
|||
} |
|||
} |
|||
} |
|||
System.out.println(); |
|||
} |
|||
} |
|||
private static final int CERTAINTY_LEVEL = 20; |
|||
} |
|||
</syntaxhighlight> |
|||
{{ out }} |
|||
<pre> |
|||
Repunit primes, up to 2700 digits, in: |
|||
Base 2: 2 3 5 7 13 17 19 31 61 89 107 127 521 607 1279 2203 2281 |
|||
Base 3: 3 7 13 71 103 541 1091 1367 1627 |
|||
Base 4: 2 |
|||
Base 5: 3 7 11 13 47 127 149 181 619 929 |
|||
Base 6: 2 3 7 29 71 127 271 509 1049 |
|||
Base 7: 5 13 131 149 1699 |
|||
Base 8: 3 |
|||
Base 9: |
|||
Base 10: 2 19 23 317 1031 |
|||
Base 11: 17 19 73 139 907 1907 2029 |
|||
Base 12: 2 3 5 19 97 109 317 353 701 |
|||
Base 13: 5 7 137 283 883 991 1021 1193 |
|||
Base 14: 3 7 19 31 41 2687 |
|||
Base 15: 3 43 73 487 2579 |
|||
Base 16: 2 |
|||
</pre> |
</pre> |
||