Miller–Rabin primality test: Difference between revisions
Content added Content deleted
(Added Java implementation) |
|||
Line 654: | Line 654: | ||
=={{header|J}}== |
=={{header|J}}== |
||
See [[j:Essays/Primality%20Tests#Miller-Rabin|Primality Tests essay on the J wiki]]. |
See [[j:Essays/Primality%20Tests#Miller-Rabin|Primality Tests essay on the J wiki]]. |
||
=={{header|Java}}== |
|||
The Miller-Rabin primality test is part of the standard library (java.math.BigInteger) |
|||
<lang java>import java.math.BigInteger; |
|||
public class MillerRabinPrimalityTest |
|||
{ |
|||
public static void main(String[] args) |
|||
{ |
|||
BigInteger n = new BigInteger(args[0]); |
|||
int certainty = Integer.parseInt(args[1]); |
|||
System.out.println(n.toString() + " is " + (n.isProbablePrime(certainty) ? "probably prime" : "composite")); |
|||
} |
|||
}</lang> |
|||
Sample output: |
|||
<pre>java MillerRabinPrimalityTest 123456791234567891234567 1000000 |
|||
123456791234567891234567 is probably prime</pre> |
|||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |