วันอังคารที่ 21 ตุลาคม พ.ศ. 2557

java.math.BigInteger.nextProbablePrime()

Description Of BigInteger: nextProbablePrime()

The java.math.BigInteger.nextProbablePrime() returns the first integer greater than this BigInteger that is probably prime. The probability that the number returned by this method is composite does not exceed 2 -100 . This method will never skip over a prime when searching: if it returns p , there is no prime q such that this < q < p

BigInteger.nextProbablePrime() method returns the first integer greater than this BigInteger that is probably prime.

Code Example Java BigInteger

import java.math.BigInteger;

public class BigIntegerExam {
 public static void main(String[] args) {
  BigInteger bi1 = new BigInteger("3");
  BigInteger bi2 = new BigInteger("20");
  BigInteger bi3 = new BigInteger("21");

  System.out.println(bi1.nextProbablePrime()); // output 3
  System.out.println(bi2.nextProbablePrime()); // output 23
  System.out.println(bi3.nextProbablePrime()); // output 23
 }
}


yengo หรือ buzzcity

ไม่มีความคิดเห็น :

แสดงความคิดเห็น