Created
April 18, 2018 19:43
-
-
Save OtherDevOpsGene/236b5ee0759ad45d34ddc852508a9475 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.coveros.benchmark; | |
import java.math.BigInteger; | |
import java.util.Date; | |
public class Prime { | |
private static final int certainty = 100; | |
public static void main(final String[] args) { | |
final long start = new Date().getTime(); | |
final int exp = Integer.valueOf(args[0]); | |
final BigInteger num = BigInteger.valueOf(2).pow(exp).subtract(BigInteger.ONE); | |
final boolean prime = num.isProbablePrime(certainty); | |
System.out.println("2^" + exp + "-1 " + (prime ? "is likely" : "is not likely") + " a Prime Number"); | |
final long end = new Date().getTime(); | |
System.out.println("Took " + (end - start) + " milliseconds."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment