How to calculate
Square and reduce the base modulo m at every step. Multiply by the reduced powers corresponding to the binary digits of the exponent.
Worked example
Use Base 3 · Modulus 13 · Exponent 100. The result is 3.
Input and result notes
Use a positive modulus. A negative exponent requires a modulus of at least 2 and a base coprime to it.