how to handle big numbers

How to handle a big number value like

Math.pow(41,77) gives a large value and I needs to take mod( % ) of that value. So I directly write a stmt as Math.pow(41,77)%119;

The correct result of this equation is 6(I know its the correct ans. *check it by calculator ). But my code returns 88 so what's wrong in my code?

How can I rewrite the same code to get the correct output.

Re: how to handle big numbers

Use a BigInteger to prevent the overflow of an int

Re: how to handle big numbers

Integer can hold 6 right? Why we need to go for big integer ?

The value of Math.pow(41,77) is 1.5 E124 this value can hold in double variable.

Re: how to handle big numbers

A double variable doesn't hold every single digit of 1.5e124. It holds a fixed "mantissa" which is ~16 digits, and an integer exponent.