Math.pow() returns a double value and takes only int as parameters...BigInteger as no function for finding BigInteger^BigInteger
Doing it through loops takes really long time...
Is there any more way i am missing?
Thnx in advance...
解决方案
You can use BigInteger.pow() to take a large exponent. Since 109 fits into an int and is also exactly representable as a double, you can do this:
int exp = (int) Math.pow(10, 9);
BigInteger answer = BigInteger.valueOf(2).pow(exp);
This obviously breaks down for exponents larger than Integer.MAX_VALUE. However, you can then use BigInteger.modPow(BigInteger exponent, BigInteger m) to raise a BigInteger to another BigInteger as a power, module a third BigInteger. You just need to first create a BigInteger that is larger than your expected answer to serve as a modulus.