MathLabs
TheoremProved

Fermat's little theorem

Statement

If pp is prime and gcd⁡(a,p)=1\gcd(a,p)=1, then ap−1≡1(modp)a^{p-1} \equiv 1 \pmod{p}. Equivalently, ap≡a(modp)a^{p} \equiv a \pmod{p} for every integer aa.

Why is it true?

The nonzero residues modulo a prime pp form a closed system under multiplication: multiplying every one of them by a fixed aa just shuffles them among themselves. Repeating this shuffle p−1p-1 times must therefore return every element to its own position, which is exactly the statement ap−1≡1(modp)a^{p-1}\equiv1\pmod p.

Proof sketch

Consider the set S={1,2,…,p−1}S=\{1,2,\dots,p-1\} of nonzero residues modulo pp, and the map x↦ax mod px \mapsto ax \bmod p sending each element of SS to a residue.

This map is injective on SS: if ax≡ay(modp)ax\equiv ay\pmod p for x,y∈Sx,y\in S, then since gcd⁡(a,p)=1\gcd(a,p)=1, the cancellation law (proved in the previous topic) gives x≡y(modp)x\equiv y\pmod p, hence x=yx=y because both lie in {1,…,p−1}\{1,\dots,p-1\}. Also no axax can be ≡0(modp)\equiv 0\pmod p for x∈Sx\in S, since pp is prime and divides neither aa nor xx. So the map actually lands back inside SS.

An injective map from the finite set SS to itself is automatically a bijection. Therefore {a⋅1,a⋅2,…,a⋅(p−1)}(modp)\{a\cdot1,a\cdot2,\dots,a\cdot(p-1)\} \pmod p is simply {1,2,…,p−1}\{1,2,\dots,p-1\} written in a different order.

Multiply all p−1p-1 elements of both sets together. On one side we get (a⋅1)(a⋅2)⋯(a⋅(p−1))=ap−1 (p−1)!(a\cdot1)(a\cdot2)\cdots(a\cdot(p-1)) = a^{p-1}\,(p-1)!; on the other, since it's the same numbers reordered, we get exactly (p−1)!(p-1)!. So ap−1(p−1)!≡(p−1)!(modp)a^{p-1}(p-1)! \equiv (p-1)! \pmod p.

Since pp is prime, none of 1,2,…,p−11,2,\dots,p-1 is divisible by pp, so gcd⁡((p−1)!,p)=1\gcd((p-1)!,p)=1. Applying the cancellation law once more to remove the common factor (p−1)!(p-1)! from both sides gives ap−1≡1(modp)a^{p-1}\equiv1\pmod p. ■\blacksquare

(Group-theoretic restatement: the nonzero residues form a group of order p−1p-1 under multiplication since pp is prime, and Lagrange's theorem says the order of any element — here, the smallest kk with ak≡1a^k\equiv1 — must divide the group's order p−1p-1; hence ap−1≡1(modp)a^{p-1}\equiv1\pmod p automatically.)

Topics that use this theorem

Step-by-step proofs

No step-by-step proof yet for this theorem.

References

  1. Ronald L. Rivest, Adi Shamir, Leonard M. Adleman (1978). A Method for Obtaining Digital Signatures and Public-Key Cryptosystems · DOI:10.1145/359340.359342
  2. W. R. Alford, Andrew Granville, Carl Pomerance (1994). There are Infinitely Many Carmichael Numbers · DOI:10.2307/2118576