Courses / Mathematics I
Arithmetic and Number Theory

Modular Arithmetic

Mathematics I 240 words Free to read

Arithmetic That Wraps Around

Modular arithmetic is the mathematics of things that cycle, like clocks and days of the week. We write:

ab(modn)a \equiv b \pmod{n}

This means aa is congruent to bb modulo nn, meaning they leave the same remainder when divided by nn, or equivalently, n(ab)n \mid (a - b). For example, 153(mod12)15 \equiv 3 \pmod{12}.

Congruence is an equivalence relation partitioning integers into nn residue classes for remainders 0,1,,n10, 1, \dots, n-1.

PropertyMeaning
Additiona+cb+da+c \equiv b+d
Multiplicationacbda \cdot c \equiv b \cdot d

Because congruence is compatible with arithmetic, you can reduce as you go. To find 1717mod517 \cdot 17 \bmod 5, use 17217 \equiv 2 to get 22=4(mod5)2 \cdot 2 = 4 \pmod 5, avoiding 289.

Two different walks around a twelve-position loop land in the same spot

The Division Exception

Division is the exception in modular arithmetic. You cannot freely divide congruences or cancel common factors as you do in standard algebra.

OperationAllowed?Rule
Add / Sub / MulYesSubstitute freely
DivisionNoRequires inverse

Common pitfall: Cancelling common factors blindly. For example, 62(mod4)6 \equiv 2 \pmod 4, but cancelling 2 gives the false statement 31(mod4)3 \equiv 1 \pmod 4.

Valid division mod nn relies entirely on multiplicative inverses, which only exist for numbers coprime to nn.

Practise this lesson

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

11practice questions
2interactive scenes

Arithmetic and Number Theory