Modulo Arithmetic Calculator

Master modular arithmetic for addition, subtraction, multiplication, exponentiation with stepwise explanations shown. Compute inverses with extended Euclid, and solve Chinese remainders under coprime moduli. Handles negatives, big integers, fast power, and nontrivial edge cases gracefully. Export history to CSV or PDF with one click.

Enter Values

Choose what to compute.
Needed for add, sub, mul, pow.

Result

Run a calculation to see the result here.

Steps

Step-by-step working will appear after computation.

History

Time (UTC) Operation Inputs Result
History persists in your browser via localStorage.

Example Data

Operation Inputs Expected Result
a mod n a=17, n=19 17
(a + b) mod n a=17, b=11, n=19 9
a^b mod n a=7, b=222, n=29 16
Inverse of a mod n a=5, n=26 No inverse (gcd=1? False; gcd=1 needed)
CRT x≡2 (mod 3), x≡3 (mod 5) x≡8 (mod 15)
Examples illustrate normalization, fast power, inverses, and CRT construction.

Formulas Used

  • (a + b) mod n = ((a mod n) + (b mod n)) mod n
  • (a - b) mod n = ((a mod n) - (b mod n)) mod n
  • (a × b) mod n = ((a mod n) × (b mod n)) mod n
  • Fast power: repeated squaring; multiply when the current exponent bit is 1.
  • Inverse exists iff gcd(a, n)=1; compute using Extended Euclid, take x mod n.
  • CRT (two congruences, coprime moduli): x = a1·M1·inv(M1,n1) + a2·M2·inv(M2,n2) (mod N), where N=n1·n2, M1=N/n1, M2=N/n2.
All results normalized to a representative in [0, n-1] for n>0.

How to Use

  1. Select an operation from the list.
  2. Enter a, optionally b, and the modulus n.
  3. For CRT, fill a1, n1, a2, n2 instead.
  4. Click Compute to see the answer and steps.
  5. Each run is saved to the history table for export.
Use gcd to check coprimality before computing inverses or CRT.

FAQs

Intermediate values in Extended Euclid can be negative. The final inverse is reduced to a nonnegative residue by taking x mod n.

Modulo arithmetic requires a nonzero modulus. The calculator flags zero as invalid to avoid undefined operations.

Yes. The fast powering algorithm handles big exponents efficiently. Extremely large inputs may still be limited by your server’s integer range.

An inverse of a (mod n) exists exactly when gcd(a,n)=1. Otherwise, no multiplicative inverse exists in that modulus.

A unique solution modulo n1·n2 requires coprime moduli. If gcd(n1,n2) ≠ 1, either no solution exists or there are multiple residue classes modulo the lcm.

Related Calculators

Proportion and Ratio Calculatorsquare root calculator with stepsnegative square root calculatorfraction square root calculatorsquare root division calculatordecimal to square root calculatorderivative of square root calculatorharmonic mean calculatorbinomial distribution mean calculatordiscrete random variable mean calculator

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.