lifekit

Search tools

Type a tool name, then press Enter to open it.

Modulo calculator

Find a mod n and the remainder for any size of number, see a = q × n + r, compare math mod with % in code, and work out modular powers.

  • Free
  • Runs in your browser
  • Nothing is uploaded

How to use it

  1. Pick a mod n for a remainder, or Power mod to work out a to the power b mod n.
  2. Enter the numbers. Negatives work, a mod n also takes decimals, and numbers can be up to 1,000 digits long.
  3. Read the remainder, the quotient, and the division written as a = q × n + r.
  4. For negative numbers, compare math mod with the % result you'd get in JavaScript, C, Python, or Excel.

Private by design

Everything runs on your device. Nothing you enter or open here is uploaded.

Questions

Divide a by n, round the quotient down to a whole number q, and subtract q × n from a; what's left is the remainder. For 17 mod 5, q = 3 and 17 − 15 = 2, so 17 = 3 × 5 + 2.

-17 mod 5 is 3 in math, because -17 = -4 × 5 + 3 and the remainder must be between 0 and 4. JavaScript, C, and Java's % operator gives -2 instead, because it truncates toward zero.

For positive numbers, yes: 17 mod 5 and the remainder of 17 ÷ 5 are both 2. With negative numbers they can differ, since math mod is never negative while the remainder from % keeps the sign of a.

Use square-and-multiply: write the exponent in binary, square the base repeatedly while reducing mod n, then multiply the squares for the 1 bits. 3¹³ mod 7 = 3⁸ × 3⁴ × 3¹ ≡ 2 × 4 × 3 ≡ 3.