Maths WorkshopMaths problems with full solutions
Exercise 1584Number theory › CongruencesL1Added 3 Nov 2026

Proving Fermat's little theorem

#Fermat#proof#permutation

Statement

Prove Fermat's little theorem: if pp is prime and p∤ap\nmid a, then ap−1≡1(modp)a^{p-1}\equiv1\pmod p.

Hint

Consider the residues a,2a,…,(p−1)aa,2a,\ldots,(p-1)a mod pp and show they are a permutation of 1,…,p−11,\ldots,p-1.

Show solutionHide solution

Solution

Permutation. The map k↦ak mod pk\mapsto ak\bmod p is injective on {1,…,p−1}\{1,\ldots,p-1\} (if ak≡aℓak\equiv a\ell, then k≡ℓk\equiv\ell since aa is invertible). So it permutes {1,…,p−1}\{1,\ldots,p-1\}.

Product. ∏k=1p−1(ak)≡∏k=1p−1k(modp)\prod_{k=1}^{p-1}(ak)\equiv\prod_{k=1}^{p-1}k\pmod p, i.e. ap−1(p−1)!≡(p−1)!(modp)a^{p-1}(p-1)!\equiv(p-1)!\pmod p.

Cancel. Since (p−1)!≢0(modp)(p-1)!\not\equiv0\pmod p (all factors are nonzero), we get ap−1≡1(modp)a^{p-1}\equiv1\pmod p.

Conclusion. Fermat's little theorem holds.