I’m doing some large integer computing, and I need to raise a BigInteger to the power of another BigInteger. The .pow() method does what I want, but takes an int value as an argument. The .modPow method takes a BigInteger as an argument, but I do not want an answer congruent to the value I’m trying to compute.
My BigInteger exponent is too large to be represented as an int, can someone suggest a way to work around this limitation?
You shouldn’t try to calculate the power of an extremely large number with another extremely large number. The resulting number would use huge amounts of memory. If you calculate
a.pow(b)it will have approximatelylog(a)*bdigits. Ifbis too large to fit in an integer then for even quite small values ofathe result will have several billion digits.Try to rethink what you are trying to achieve and how to achieve it without doing this operation.