Skip to content

Instantly share code, notes, and snippets.

@OtherDevOpsGene
Created April 18, 2018 19:43
Show Gist options
  • Save OtherDevOpsGene/236b5ee0759ad45d34ddc852508a9475 to your computer and use it in GitHub Desktop.
Save OtherDevOpsGene/236b5ee0759ad45d34ddc852508a9475 to your computer and use it in GitHub Desktop.
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