Number Theory: Modular Arithmetic

Study Sheet

Number Theory: Modular Arithmetic

Congruences, Fermat, and bases

Working Modulo n

Tip
Congruence arithmetic

ab(modn)a\equiv b\pmod n means n(ab)n\mid(a-b). You may add, subtract, and multiply congruences.

In plain terms. Only the remainder matters, so replace big numbers by their remainders and do easy arithmetic.

Example. 3100mod53^{100}\bmod 5: since 34=8113^4 = 81\equiv 1, 3100=(34)2513^{100} = (3^4)^{25}\equiv 1.

Tip
Fermat's little theorem

If pp is prime and pap\nmid a, then ap11(modp)a^{p-1}\equiv 1\pmod p.

In plain terms. Raising to the power p1p-1 resets you to 11 modulo a prime, so huge exponents shrink fast.

Example. 2100mod72^{100}\bmod 7: 2612^6\equiv 1, and 100=616+4100 = 6\cdot 16 + 4, so 210024=1622^{100}\equiv 2^4 = 16\equiv 2.