0

Java BigInteger class has built-in nextProbablePrime() method which gives next prime number of current BigInteger. I want do it reverse direction.

How do I get previous prime number? Is there any other way get this prime instead of manual checking?

  • 2
    "which gives next prime number of current BigInteger" - It does not give the next prime, but rather a *probable prime*. It is still possible for the method to return a composite number. – Jacob G. Aug 06 '19 at 02:22
  • I stumbled across this - https://en.wikipedia.org/wiki/Sieve_of_Atkin and https://stackoverflow.com/questions/10580159/sieve-of-atkin-explanation-and-java-example – David Brossard Aug 06 '19 at 02:22
  • 1
    If you want an actual prime, use the sieve as @DavidBrossard has suggested. If you want a _probable_ prime, just check numbers smaller than your number with `isProbablePrime`. – Sweeper Aug 06 '19 at 02:40
  • 1
    Not sure what you mean by *manual checking* but, no, there is no method for `previousProbablyPrime()` so you'll need to write or obtain your own code for it. – President James K. Polk Aug 06 '19 at 17:35

0 Answers0