Can someone explain why this works?
5^101 mod 124 = 5^(101 mod 3) mod 124 = 5^2 mod 124 = 25
How did they know to choose 3 in the problem above? If given a problem like this, I don't see how I would deduce that I need to take 101 mod 3 to make the problem easier.
Edit: Is there a general formula for this? Can I use this in any problem with a large exponent?
Re: Modular arithmetic
note that 53 = 125 = 1 (mod 124).
so if n = 3k + t (that is: n = t (mod 3))
5n = (53k)(5t) = (53)k(5t) = (1k)(5t) = 5t (mod 124).