Java BigInteger modPow() method

The modPow() method of Java BigInteger class is used to perform modular exponentiation. This method returns a BigInteger whose value is (thisexponent mod parameter value). This method first calculates the pow() method then applies the mod() method. This method allows negative exponents.

Syntax:

Parameter:

exponent- The Exponent.

m- The modulus.

Returns:

This method returns (thisexponent mod m).

Exception:

ArithmeticException - m ≤ 0

Example 1

Test it Now

Output:

13^2 mod 5 is 4

Example 2

Test it Now

Output:

java.lang.ArithmeticException: BigInteger: modulus not positive

Example 3

Test it Now

Output:

13^-2 mod 5 is 4

Example 4

Test it Now

Output:

-13^-2 mod 5 is 4

Next TopicJava BigInteger




Latest Courses