modPow(): This method is available in java.math.BigInteger class of Java.
Syntax:
BigInteger java.math.BigInteger.modPow(BigInteger exponent, BigInteger m)
This method takes two arguments of type BigInteger as its parameters. This method returns a BigInteger whose value is (this exponent mod m). (Unlike pow, this method permits negative exponents.)
Parameters: Two parameters are required for this method.
exponent: the exponent.
m: the modulus.
Returns: this^exponent mod m.'
Throws: ArithmeticException - m ≤ 0 or the exponent is negative and this BigInteger is not relatively prime to m.
For Example:
BigInteger bigInteger = new BigInteger("1234")
BigInteger exponent = new BigInteger("4")
BigInteger m = new BigInteger("101")
bigInteger.modPow(exponent,m) = > It returns 37.
Approach
Java
import java.math.BigInteger;public class BigIntegermodPow {public static void main(String[] args) {BigInteger bigInteger = new BigInteger("1234");BigInteger exponent = new BigInteger("4");BigInteger m = new BigInteger("101");System.out.println(bigInteger.modPow(exponent, m));}}
Output:
37
No comments:
Post a Comment