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

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.