# Multiplication Modulo n

> See the multiplication table of the integers modulo n, colored by units, zero divisors and idempotents. Move the slider n from 2 to 60.

On a 12-hour clock, 8 hours after 7 o'clock is 3 o'clock: the clock keeps only the remainder after division by 12. Gauss made this arithmetic a tool of number theory in Disquisitiones Arithmeticae (1801), and today it is the base of public-key cryptography such as RSA. Modulo $n$, only the remainders $0, 1, \ldots, n - 1$ exist, and a product is replaced by its remainder after division by $n$. In the table, the cell in column $u$ and row $v$, counted from 0 at the bottom left, holds $z = uv \bmod n$.

A unit has an inverse, a number $w$ with $zw \bmod n = 1$; $z$ is a unit when $\gcd(z, n) = 1$ ($z$ and $n$ share no factor but 1), and there are $\varphi(n)$ of them, where $\varphi$ is Euler's totient function. Units are colored from green through blue to pink by their value, and 1 is white. The rows and columns of the units hold each unit exactly once, so their colored cells form a Latin square: the units form a group under multiplication. Every other nonzero number is a zero divisor: its product with some nonzero number is 0. Zero divisors are gray, and 0 is dark. An idempotent is a number with $z^2 \bmod n = z$; those other than 0 and 1 are zero divisors, colored gold. When $n$ has $k$ different prime factors, there are $2^k$ idempotents, 0 and 1 included.

When $n$ is prime, every number but 0 is a unit: the table has no gray or gold, and arithmetic modulo $n$ is a field: division works too. When $n$ has many small factors, as 24, 30 or 60, gray cells fill most of the table. Set $n = 30 = 2 \cdot 3 \cdot 5$ and notice its $2^3 = 8$ idempotents, six of them gold.

- [Open the interactive version](https://graph-paper.io/showcase/en/multiplication-mod-n)
- [Learn more on Wikipedia](https://en.wikipedia.org/wiki/Multiplicative_group_of_integers_modulo_n)
