#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
⚡ FREE · ANY SIZE

Modulo Calculator: mod, Powers, Inverses and GCD, with Steps

Work out remainders, huge modular powers, inverses and GCDs exactly, with the working shown.

  • ➗ Negative numbers explained
  • ⚡ Fast modular powers
  • 🔁 Inverse and GCD steps

How to use the Modulo Calculator

  1. 1. Pick a calculationmod, modular power, modular inverse, or GCD and LCM.
  2. 2. Enter whole numbersAny size; they're handled exactly.
  3. 3. Read the stepsSee each stage of the algorithm.

What the calculator does

  • a mod n: the remainder when a is divided by n. For negative numbers, languages disagree: maths and Python give a result with the sign of n, while C, Java and JavaScript's % keeps the sign of a. The tool shows both.
  • Modular power aᵇ mod n uses square-and-multiply, so even 3^1000000 mod 13 takes about 20 steps instead of a million multiplications. This is how RSA encryption works.
  • Modular inverse a⁻¹ mod n is the number x with a × x ≡ 1 (mod n). It exists only when gcd(a, n) = 1, and is found with the extended Euclidean algorithm.
  • GCD and LCM use Euclid's algorithm: replace (a, b) with (b, a mod b) until b is 0.

All maths uses BigInt, so numbers with hundreds of digits are exact.

Worked examples

  • −17 mod 5 = 3, because −17 = 5 × (−4) + 3. In C, Java or JavaScript, −17 % 5 gives −2, because the quotient is cut towards zero (−3). Python's −17 % 5 gives 3.
  • 3^200 mod 13 = 9, using 8 squarings, one for each bit of 200.
  • 3⁻¹ mod 11 = 4, because 3 × 4 = 12 = 11 + 1.
  • gcd(84, 36) = 12: 84 mod 36 = 12, then 36 mod 12 = 0. The LCM is 84 × 36 ÷ 12 = 252.

These come up in competitive programming (answers "modulo 10⁹ + 7"), cryptography, hashing and number-theory exam questions. When an answer must be taken mod 10⁹ + 7, take the remainder after every multiplication to keep the numbers small.

Frequently asked questions

Why do programming languages give different answers for negatives?

They define integer division differently. Truncating towards zero gives a remainder with a's sign; flooring gives one with n's sign.

What is 10⁹ + 7 and why is it used?

1,000,000,007 is a large prime that fits in 32 bits, so contest answers can be compared without overflow, and modular inverses exist for every non-zero number.

Can the exponent be huge?

Yes. Square-and-multiply needs only as many steps as the exponent has bits.

Is the modulo calculator free to use?

Yes, the modulo calculator is free and costs nothing. Your first calculation shows a short form for your name and WhatsApp number one time; once that's done, this tool and every other Uncodemy tool open with no form.

More free tools

See all free tools