BigInteger isProbablePrime() in Java

isProbablePrime(): This method is available in java.math.BigInteger class of Java.

Syntax:

boolean java.math.BigInteger.isProbablePrime(int certainty)

This method takes one argument of type int as its parameter. This method returns true if this BigInteger is probably prime, false if it's definitely composite. If certainty is ≤ 0, true is returned.

Parameters: certainty is 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/2certainty). The execution time of this method is proportional to the value of this parameter.

Returns: true if this BigInteger is probably prime, false if it's definitely composite.

For Example:

BigInteger bigInteger = new BigInteger("101")

int certainity = 15

bigInteger.isProbablePrime(certainity) = > It returns true.

Approach

Java

import java.math.BigInteger;

public class BigIntegerisProbablePrime {
    public static void main(String[] args) {

        BigInteger bigInteger = new BigInteger("101");
        int certainity = 15;
        System.out.println(bigInteger.isProbablePrime(
certainity));
    }
}

Output:

true

No comments:

Post a Comment