Modular exponentiation calculator
Compute the residue of an integer power with repeated squaring. Your inputs stay on your device.
Set up your task
Starting local processing
Ready. Processing stays in this browser.
2 Your result
Your result updates in this browser. Check your input if the result looks unexpected.
How to use Modular exponentiation calculator
Compute the residue of an integer power with repeated squaring. The pre-filled problem gives you a worked starting point. Compare the response with your own working before trying the self-check below.
- Check the example inputs: Base, Exponent, Modulus.
- Change the inputs for your problem. Results update as you type, so finish entering the values before copying an answer.
- Use the working to check an intermediate value or assumption. Then change the example as suggested in the self-check and compare the result.
Supported inputs and limits
Use integers up to 40 digits, a modulus of at least 2, and a non-negative exponent. A negative base is allowed.
How it works
Modular exponentiation computes a power’s remainder without constructing the enormous power itself. Congruent integers can be substituted during multiplication. Consequently every multiplication can be reduced modulo m immediately, which bounds the intermediate values by the size of the modulus.
Repeated squaring walks through the binary expansion of the exponent. Square the base for each successive bit and multiply the accumulator for a set bit. This takes a number of modular multiplications proportional to the number of exponent bits. The normalised residue starts at zero and is smaller than the modulus.
Example
Run the pre-filled example. Its first result is “Power residue: 7”.
- Base
- 7
- Exponent
- 13
- Modulus
- 19
Power residue: 7 Normalised base: 7 Exponent bits: 4 Repeated squaring reduces after every multiplication.
Questions about Modular exponentiation calculator
What is the residue when the exponent is zero?
The multiplicative identity is 1 for any permitted modulus. The calculation uses that convention even when the base itself is zero.
How does a negative base work?
The tool first replaces it with the corresponding non-negative residue. This replacement preserves every later congruence.
Calculate −2 to the power 3 modulo 5.
The remainder is 2, since −8 differs from 2 by twice the modulus. A language’s percent operator may instead return a negative raw remainder.
Related tools
Last updated