Modular arithmetic calculator

Evaluate an expression with plus, minus, times, division and powers modulo n, every operation shown and reduced.

How it works

Modulo $n$ you can add, subtract and multiply as usual and reduce the result at any moment: if $a \equiv a'$ and $b \equiv b' \pmod n$, then $a + b \equiv a' + b'$ and $a b \equiv a' b'$. So an expression is evaluated from the inside out, and every intermediate value is replaced by its remainder, which keeps the numbers small.

Division is different: $x / y$ means $x \cdot y^{-1}$, where $y^{-1}$ is the number with $y \cdot y^{-1} \equiv 1$. It exists only when $\gcd(y, n) = 1$. Modulo $11$, $1/2 + 1/3 \equiv 6 + 4 = 10$. The ordinary sum of fractions is $5/6$, and indeed $5/6 \equiv 5 \cdot 2 = 10$, since $6^{-1} \equiv 2$: fractions with denominators coprime to $n$ behave modulo $n$ exactly as they should.

Exponents are the exception to reducing: they count multiplications, so they are whole numbers and are not reduced modulo $n$ (with $\gcd(a, n) = 1$ they could be reduced modulo $\varphi(n)$ instead). A negative exponent is a power of the inverse.

Everything is calculated in your browser. Nothing you type leaves your device.