Skip to content

Fermat's little theorem ​

Consider modular arithmetic under modulo mm. We fix number aa so that gcd(a,m)=1{\sf gcd}(a,m)=1. Let us write a function fa:[m−1]→[m−1]f_a: [m-1] \rightarrow [m-1] where fa(x)=a⋅x(modm)f_a(x) = a \cdot x \pmod{m}. We argued before (when we proved that the inverse exists) that faf_a is a bijection. Therefore,

∏x∈[m−1]∖{0}x≡∏x∈[m−1]∖{0}a⋅x(modm)\prod_{x\in[m-1]\setminus \{0\}​} x \equiv \prod_{x \in [m-1]\setminus \{0\}​}a\cdot x \pmod{m}

This gives us (am−1−1)(m−1)!≡0(modm)(a^{m-1}-1)(m-1)! \equiv 0 \pmod{m}. Equivalently, mm divides (am−1−1)(m−1)!(a^{m-1}-1)(m-1)!. When mm is prime, we know that mm divides am−1−1a^{m-1} -1.

Theorem 18 (Fermat's little theorem (F$\ell$T))

For any prime pp and number aa that is not divisible by pp, we have ap−1≡1(modp)a^{p-1} \equiv 1 \pmod{p}.

Remark the distinction between the elementary F$\ell$T and the much-more-difficult-to-prove Fermat's Last Theorem (FLT). The correctness of RSA follows from a simple application of F$\ell$T.

Theorem 19 (Correctness of RSA)

We have that xe⋅d≡x(modN)x^{e\cdot d} \equiv x \pmod{N}.

Proof:

Since

e⋅d≡1(mod(p−1)(q−1))e \cdot d \equiv 1 \pmod{(p-1)(q-1)}

, we can write e⋅d=1+k(p−1)(q−1)e \cdot d = 1+ k (p-1)(q-1) for some integer kk. Therefore,

xe⋅d≡x1+k(p−1)(q−1)(modN)x^{e \cdot d} \equiv x^{1+k(p-1) (q-1)} \pmod{N}

We argue that x1+k(p−1)(q−1)≡x(modp)x^{1+k(p-1)(q-1)} \equiv x \pmod{p} and x1+k(p−1)(q−1)≡x(modq)x^{1+k(p-1)(q-1)} \equiv x \pmod{q}, which would imply the desired result (do you see why?). We only prove the former claim (the latter case is symmetrical). To prove x1+k(p−1)(q−1)≡x(modp)x^{1+k(p-1)(q-1)} \equiv x \pmod{p}, we consider two cases:

  • If xx is divisible by pp, notice that x1+k(p−1)(q−1)−xx^{1+k(p-1)(q-1)} - x is also divisible by pp.
  • If xx is not divisible by pp, we can apply F$\ell$T to obtain xp−1≡1(modp)x^{p-1} \equiv 1 \pmod{p} and therefore

x1+k(p−1)(q−1)≡x(modp)x^{1+k(p-1)(q-1)} \equiv x \pmod{p}

Exercise 49

Prove that x10≢−1(mod31)x^{10} \not\equiv -1 \pmod{31} for all integer xx. Your proof should be at most a few lines (in particular, do not list all possible choices of xx).

Toolbox by Hilmy Abiyyu Asad from the Noun Project. © 2026 Me. Built with VitePress.