Fermat's Little Theorem

For prime p, a^{p-1} ≡ 1 (mod p) when p ∤ a.
Fermat's Little Theorem

Fermat’s Little Theorem: Let pp be a prime and let aZa \in \mathbb{Z}. Then

apa(modp).a^p \equiv a \pmod p.

Equivalently, if pap \nmid a (i.e., a≢0(modp)a \not\equiv 0 \pmod p), then

ap11(modp).a^{p-1} \equiv 1 \pmod p.

Here xy(modp)x \equiv y \pmod p means that pp divides xyx-y.

This is a standard application of to the (Z/pZ)×(\mathbb{Z}/p\mathbb{Z})^\times, a finite of order p1p-1. It is also the prime-modulus special case of (since φ(p)=p1\varphi(p)=p-1).

Proof sketch (group-theoretic): If pap \nmid a, the residue class of aa is an element of (Z/pZ)×(\mathbb{Z}/p\mathbb{Z})^\times. By Lagrange’s theorem, raising any element to the power p1p-1 gives the identity in this group, which translates exactly to the congruence ap11(modp)a^{p-1} \equiv 1 \pmod p.

Examples:

  • p=7p=7, a=3a=3: 36=729=7104+13^{6}=729=7\cdot 104+1, so 361(mod7)3^{6}\equiv 1 \pmod 7.
  • p=5p=5, a=10a=10: both 10510^5 and 1010 are divisible by 55, so 10510(mod5)10^5 \equiv 10 \pmod 5 (this is the “apaa^p \equiv a” form).
  • If pap \nmid a, then ap2a^{p-2} is a multiplicative inverse of aa modulo pp (since aap2=ap11a\cdot a^{p-2}=a^{p-1}\equiv 1). For instance, with p=7p=7, a=3a=3: 35=243=734+53^{5}=243=7\cdot 34+5, so 315(mod7)3^{-1}\equiv 5 \pmod 7 because 35=151(mod7)3\cdot 5=15\equiv 1 \pmod 7.