finding a^b^c^… mod m

abc mod m = abc mod n mod m, where n = φ(m) Euler’s totient function.

If m is prime, then n = m-1.

Edit: as Nabb pointed out, this only holds if a is coprime to m. So you would have to check this first.

Leave a Comment