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.
Now my question : the editorial suggests a value of 1 for the parameter of isProbablePrime, and many solution here suggests the same. I don't understand why.
The doc of isProbablePrime says : "Parameter certainty - a measure of the uncertainty that the caller is willing to tolerate: if the call returns true the probability that this BigInteger is prime exceeds (1 - (1/2)^certainty). The execution time of this method is proportional to the value of this parameter."
So it seems to me that a small value (1) would provide an important risk of false positive (the probability that the number tested is prime exceeds 1 - (1/2)^1 = 0.5 = 50%), and that using a bigger number as parameter would provide much more certainty ?
Since here we're looking for precision and not speed, it seems far more safe to give the parameter a bigger value.
In fact, I'm surprised that all the tests cases pass with a value of 1.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Primality Test
You are viewing a single comment's thread. Return to all comments →
My solution :
Now my question : the editorial suggests a value of 1 for the parameter of isProbablePrime, and many solution here suggests the same. I don't understand why.
The doc of
isProbablePrime
says : "Parameter certainty - a measure of the uncertainty that the caller is willing to tolerate: if the call returns true the probability that this BigInteger is prime exceeds (1 - (1/2)^certainty). The execution time of this method is proportional to the value of this parameter."So it seems to me that a small value (1) would provide an important risk of false positive (the probability that the number tested is prime exceeds 1 - (1/2)^1 = 0.5 = 50%), and that using a bigger number as parameter would provide much more certainty ?
Since here we're looking for precision and not speed, it seems far more safe to give the parameter a bigger value.
In fact, I'm surprised that all the tests cases pass with a value of 1.