We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I use isProbablePrime() with certainty = 10 to achieve 99.9% accuracy. However, even certainty = 1 (which achieves 50% accuracy) is enough to pass the test cases.
This function 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.
Java Primality Test
You are viewing a single comment's thread. Return to all comments →
Java solution - passes 100% of test cases
From my HackerRank solutions.
I use isProbablePrime() with certainty = 10 to achieve 99.9% accuracy. However, even certainty = 1 (which achieves 50% accuracy) is enough to pass the test cases.
This function 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.
Let me know if you have any questions.