Modular Arithmetic Calculator
Compute a mod m, sums, products, powers, modular inverses and Euler's totient. Handles big numbers.
How it works
Pick an operation and type the numbers. Powers use fast exponentiation (repeated squaring), so even huge exponents are quick. The inverse of a modulo m uses the extended Euclidean algorithm and exists only when gcd(a, m) is 1.
The formula
a^b mod m by repeated squaring inverse: a x a^-1 = 1 (mod m) phi(m) = m x product of (1 - 1/p) over primes p dividing m
Worked example
3^200 mod 13: 3^3 = 27 = 1 (mod 13), so 3^200 = 3^(3 x 66 + 2) = 3^2 = 9. The inverse of 3 mod 13 is 9 because 3 x 9 = 27 = 1 (mod 13).
Good to know
- Negative numbers work: -7 mod 5 is 3, not -2.
- Fermat: if p is prime and a is not a multiple of p, a^(p-1) = 1 (mod p).
- RSA uses these exact operations with very large numbers.
Common questions
- Why does my inverse not exist?
- a and m share a factor. For example 4 has no inverse mod 8.
- What is the Bezout coefficient?
- The x in a x + b y = gcd(a, b).
- How large can the numbers be?
- Very large. The calculator uses big integers.
More in CS Labs & Coding.
Watch 10 sorting algorithms animate step by step with live counters and pseudocode, or race them on the same input.
CS Labs & CodingTOP PICKGraph Algorithm VisualizerTOP PICKDraw your own graph and watch BFS, DFS, Dijkstra, Bellman-Ford, Prim, Kruskal, topological sort and more run step by step, with the queue, the distance table and the reason for every move.
Big-O Estimator from TimingsTime your code on a few input sizes, paste the numbers, and see which growth rate fits best.
OPEN →