Files

28 lines
854 B
Java
Raw Permalink Normal View History

2017-02-16 23:51:56 -06:00
// Author: Rodney Shaghoulian
2018-07-27 16:45:56 -07:00
// Github: github.com/RodneyShag
// HackerRank: hackerrank.com/RodneyShag
2017-02-16 23:51:56 -06:00
import java.util.Scanner;
import java.math.BigInteger;
/*
I use isProbablePrime() with certainty = 10 to achieve 99.9% accuracy.
However, even certainty = 1 (which achieves 50% accuracy) is enough to
pass the HackerRank test cases.
isProbablePrime() is always 100% certain if it tells you if a number
is "not prime". If it says "prime", it's only 99.9% certain. It may be
the case that it just hasn't found a prime number number that divides
the BigInteger yet.
*/
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
BigInteger n = scan.nextBigInteger();
scan.close();
System.out.println(n.isProbablePrime(10) ? "prime" : "not prime");
}
}