dash–calculator

04 Numbers and Counting

Remainder Calculator with Powers

Readout 04-0245 · Updated · Standard formula, shown below

The calculator on this page is switched off while it is checked. The formula is below, and the worked example shows how to do the sum by hand.

This calculator finds the remainder when one number is divided by another, but it also handles expressions with powers, such as 7^100 mod 13. You enter a base, an exponent, and a divisor (modulus), and the calculator returns the remainder using modular exponentiation, which avoids computing the enormous intermediate power.

Formula

The core formula is modular exponentiation: ab mod m = the remainder when ab is divided by m. The calculator uses the binary method (also called square-and-multiply) to compute this efficiently. The variables are:

  • a (base) – the number being raised to a power.
  • b (exponent) – how many times the base is multiplied by itself.
  • m (modulus) – the divisor; must be a positive integer.

Because the result of ab can be astronomically large (e.g., 7100 has 85 digits), the calculator reduces intermediate results modulo m at each step, keeping numbers small.

Worked Example

Using the defaults: a = 7, b = 100, m = 13. We want 7100 mod 13.

  1. Write the exponent 100 in binary: 100 = 64 + 32 + 4, so binary is 1100100.
  2. Start with result = 1, base = 7 mod 13 = 7.
  3. Process bits from right to left:
    • Bit 0 (0): square base → 7² = 49 mod 13 = 10, base = 10.
    • Bit 0 (0): square base → 10² = 100 mod 13 = 9, base = 9.
    • Bit 1 (1): result = result × base = 1 × 9 = 9, then square base → 9² = 81 mod 13 = 3, base = 3.
    • Bit 0 (0): square base → 3² = 9 mod 13 = 9, base = 9.
    • Bit 0 (0): square base → 9² = 81 mod 13 = 3, base = 3.
    • Bit 1 (1): result = 9 × 3 = 27 mod 13 = 1, then square base → 3² = 9, base = 9.
    • Bit 1 (1): result = 1 × 9 = 9, then square base → 9² = 81 mod 13 = 3.
  4. Final result = 9. So 7100 mod 13 = 9.

You can verify with a smaller exponent: 7² = 49, 49 mod 13 = 10, and the calculator gives the same.

Why Use Modular Exponentiation?

Computing ab directly is impractical for large exponents. For example, 21000 has 302 digits – your calculator or phone may overflow. Modular exponentiation reduces the problem to multiplications of numbers less than m, so even exponents like 106 are handled instantly. This method is the backbone of RSA encryption, where exponents are often hundreds of digits long.

In everyday math, you might need remainders of powers when working with cyclic patterns (e.g., finding the day of the week after a large number of days) or in programming contests.

How to Read the Result

The output is the remainder, an integer between 0 and m-1. If the remainder is 0, then m divides ab exactly. For example, 23 mod 4 = 0 because 8 is divisible by 4.

Note that the remainder is always non-negative. In some programming languages, the modulo operator with negative numbers can return a negative result, but here we use the mathematical definition.

Common Mistakes and Pitfalls

  • Using a negative exponent: The calculator expects a non-negative exponent. For negative exponents, you need modular inverse, which is a different concept.
  • Modulus of 1: Any number mod 1 is 0, so the result will always be 0. The calculator allows m=1, but it’s a trivial case.
  • Confusing modulo with remainder: For positive numbers they are the same, but for negative bases, the remainder can be negative if you use truncation. This calculator uses the Euclidean definition (always non-negative).
  • Rounding errors: The calculator uses exact integer arithmetic, so no floating-point errors.

Alternatives and Related Calculations

If you need just a simple remainder without powers, use a standard modulo calculator. For finding powers without a modulus, use a power calculator. If you need to solve for x in ax ≡ b (mod m), that is a discrete logarithm problem, which is much harder and not implemented here.

For very large exponents (beyond 106), the calculator may still work but could be slow. In such cases, consider using a programming language with big integer support.

Frequently Asked Questions

What is the remainder of 2^100 mod 3?

Using the calculator: base=2, exponent=100, modulus=3. Since 2 mod 3 = -1, and 100 is even, (-1)^100 = 1, so the remainder is 1. The calculator will output 1.

Can I use a negative base?

Yes, but the calculator’s input minimum is 0 for base. For negative bases, you can enter a positive base and then adjust the result: if the exponent is odd, the remainder is (positive remainder) – m; if even, it’s the positive remainder. For example, (-2)^3 mod 5 = -8 mod 5 = 2, but the calculator with base=2, exp=3, mod=5 gives 3, which is incorrect for the negative base. To get the correct answer, subtract m: 3 – 5 = -2, then add m to get 3? Actually, -8 mod 5 = 2, so you need to compute the positive base result (8 mod 5 = 3) and then because exponent is odd, the true remainder is 3 – 5 = -2, but the mathematical remainder is 2. So it’s easier to just enter the absolute value and then adjust manually. The calculator does not accept negative bases to avoid confusion.

What if the exponent is 0?

Any number to the power 0 is 1, so the remainder is 1 mod m, unless m=1 then it’s 0. The calculator handles this correctly.

How does this help with large exponents in real life?

It’s used in cryptography (RSA), hash functions, and random number generators. For example, calculating a^b mod n is a core step in RSA encryption and decryption.

Is there a limit to the size of the numbers?

The calculator allows inputs up to 1,000,000 for each field. For larger numbers, you would need a specialized tool or programming language. The algorithm itself can handle much larger numbers, but the browser’s JavaScript engine may become slow.

Related

Formula used
in base | Base (a) | - | 7 | 0 | 1000000
in exp | Exponent (b) | - | 100 | 0 | 1000000
in mod | Divisor (m) | - | 13 | 1 | 1000000
out rem | Remainder (a^b mod m) | - | pow(base, exp) mod mod | 0

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More on this panel

The whole Numbers and Counting panel →