khashayar
khashayar

Reputation: 33

How to power up a huge number in java?

I looking for a way to power up a number and finding mod, something like this in python
pow(x, y, z)
for example x ^ y % z
x is about 3 digits, y is about 450 digits, and z is about 400 digits
thanks in advance

Upvotes: 0

Views: 209

Answers (1)

kkica
kkica

Reputation: 4104

The method you are looking for: public BigInteger modPow(BigInteger exponent,BigInteger m)

Usage:

BigInteger base= new BigInteger("111");
BigInteger exponent= new BigInteger(yourExponent);
BigInteger m= new BigInteger(yourM);
System.out.println(base.modPow(exponent,m));

For limitations of BigInteger see this question

Upvotes: 7

Related Questions