Java BigInteger modInverse() method

The modInverse() method of Java BigInteger class is used to find the modulus of the inverse of this BigInteger value. This method returns a BigInteger whose value is inverse of this BigInteger mod parameter value.

Syntax:

Parameter:

m- the modulus.

Returns:

The method returns (this-1 mod m).

Exception:

ArithmeticException - if(m ≤ 0).

Note: This method throws an ArithmeticException if the inverse of this BigInteger does not exist (that is, this BigInteger is not relatively prime to parameter value).

Example 1

Test it Now

Output:

13^-1 % 5 is 2

Example 2

Test it Now

Output:

-13^-1 % 5 is 3

Example 3

Test it Now

Output:

java.lang.ArithmeticException: BigInteger: modulus not positive

Example 4

Test it Now

Output:

java.lang.ArithmeticException: BigInteger: modulus not positive

Next TopicJava BigInteger




Latest Courses