BigInteger modPow() Method in Java Last Updated : 11 Aug, 2021 Comments Improve Suggest changes Like Article Like Report Prerequisite: BigInteger BasicsThe Java.math.BigInteger.modPow() method returns a BigInteger whose value is (thisexponent mod m ). If exponent == 1, the returned value is (this mod m) and if exponent < 0, the returned value is the modular multiplicative inverse of (this-exponent). The method throws an ArithmeticException if m <= 0. Syntax: public BigInteger modPow(BigInteger exponent, BigInteger m) Parameters: The method accepts two parameters. exponent: This parameter refers to the exponent.m: This parameter refers to the modulus. Return Value: The method returns a BigInteger object whose value is ( thisexponent mod m ). Exceptions: ArithmeticException: If (m <= 0) or the exponent is negative and this BigInteger is not relatively prime to m. Examples: Input: biginteger1 = 23895 exponent = 15 biginteger2 = 14189 Output: 344 Explanation: result = biginteger1.modPow(exponent, biginteger2) 23895^15 % 14189 = 344 Input: biginteger1 = 6547890621 exponent = 4532415 biginteger2 = 76543278906 Output: 1039609179 Explanation: 6547890621^4532415 % 76543278906 = 1039609179 Below program illustrates the Java.math.BigInteger.modPow() method: Java // Code to illustrate modpow() method of BigInteger import java.math.*; import java.util.Scanner; public class GFG { public static void main(String[] args) { // Create 3 BigInteger objects BigInteger biginteger1, biginteger2, result; // Initializing all BigInteger Objects biginteger1 = new BigInteger("23895"); biginteger2 = new BigInteger("14189"); BigInteger exponent = new BigInteger("15"); // Perform modPow operation on the objects and exponent result = biginteger1.modPow(exponent, biginteger2); String expression = biginteger1 + "^" + exponent + " % " + biginteger2 + " = " + result; // Displaying the result System.out.println(expression); } } Output: 23895^15 % 14189 = 344 Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#abs() Comment More infoAdvertise with us Next Article BigInteger modPow() Method in Java A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions java-math Java-BigInteger Java-math-package +1 More Practice Tags : JavaJava-BigInteger Similar Reads BigInteger mod() Method in Java The java.math.BigInteger.mod(BigInteger big) method returns a BigInteger whose value is equal to (this BigInteger modfunction big(BigInteger passed as parameter)).In other words we can say that this method returns the value after performing (this % big) step.The mod operation finds the remainder aft 3 min read BigInteger pow() Method in Java The java.math.BigInteger.pow(int exponent) method is used to calculate a BigInteger raise to the power of some other number passed as exponent whose value is equal to (this)exponent. This method performs operation upon the current BigInteger by which this method is called and exponent passed as para 2 min read BigInteger or() method in Java Prerequisite: BigInteger Basics The java.math.BigInteger.or(BigInteger val) method is used to perform bitwise OR of two BigIntegers. One of the BigInteger is passed in parameter and the other on which the function is called. This method returns a negative number if either of the BigIntegers used wit 2 min read BigInteger xor() Method in Java Prerequisite: BigInteger Basics The xor(BigInteger val) method returns bitwise-XOR of two bigIntegers. This method returns a negative BigInteger if and only if exactly one of the current bigInteger and the bigInteger passed in parameter id negative. The xor() method of BigInteger class apply bitwise 2 min read BigInteger not() Method in Java The java.math.BigInteger.not() method is used to find the bitwise-NOT of a BigInteger. This method returns a negative value if and only if this BigInteger is non-negative. The BigInteger.not() method apply bitwise Not operation upon the current bigInteger. Syntax: public BigInteger not() Parameters: 1 min read Like