Euler's Totient Function

lean4-proofnumber-theorymodular-arithmeticgroup-theoryvisualization
aφ(n)1(modn)a^{\varphi(n)} \equiv 1 \pmod{n}

Statement

The Euler totient function φ(n)\varphi(n) counts the integers in {1,,n}\{1, \ldots, n\} that are coprime to nn:

φ(n)=#{k:1kn, gcd(k,n)=1}\varphi(n) = \#\{k : 1 \le k \le n,\ \gcd(k, n) = 1\}

Euler's theorem says: for any aa with gcd(a,n)=1\gcd(a, n) = 1,

aφ(n)1(modn)a^{\varphi(n)} \equiv 1 \pmod{n}

This generalises Fermat's Little TheoremFermat's Little Theoremapa(modp)a^p \equiv a \pmod{p}For prime p, a^p is congruent to a mod pRead more → (which is the special case n=pn = p prime, φ(p)=p1\varphi(p) = p-1).

Visualization

Totient values for small nn:

nnCoprime residuesφ(n)\varphi(n)
1{1}\{1\}1
2{1}\{1\}1
4{1,3}\{1, 3\}2
6{1,5}\{1, 5\}2
8{1,3,5,7}\{1, 3, 5, 7\}4
9{1,2,4,5,7,8}\{1, 2, 4, 5, 7, 8\}6
10{1,3,7,9}\{1, 3, 7, 9\}4
12{1,5,7,11}\{1, 5, 7, 11\}4

Key formulas:

φ(p)      = p - 1              (p prime)
φ(p^k)    = p^k - p^(k-1)     = p^(k-1)(p - 1)
φ(mn)     = φ(m)φ(n)          if gcd(m,n) = 1   (multiplicativity)
φ(n)      = n · ∏_{p | n} (1 - 1/p)             (general formula)

Euler's theorem trace for a=3a = 3, n=10n = 10, φ(10)=4\varphi(10) = 4:

3^1  =   3  ≡ 3 (mod 10)
3^2  =   9  ≡ 9 (mod 10)
3^3  =  27  ≡ 7 (mod 10)
3^4  =  81  ≡ 1 (mod 10)   ← 3^φ(10) ≡ 1 ✓

Group structure: the units (Z/nZ)×(\mathbb{Z}/n\mathbb{Z})^\times form a group of order φ(n)\varphi(n). Euler's theorem is just Lagrange's theorem applied to aa in this group.

Proof Sketch

  1. The units form a group. (Z/nZ)×={amodn:gcd(a,n)=1}(\mathbb{Z}/n\mathbb{Z})^\times = \{a \bmod n : \gcd(a,n) = 1\} is a multiplicative group of order φ(n)\varphi(n) (closure under multiplication uses Bezout's IdentityBezout's Identitygcd(a,b)=ax+by\gcd(a,b) = a \cdot x + b \cdot yThe gcd of two integers is always an integer linear combination of those integersRead more → to show the product of two coprime-to-nn elements stays coprime to nn).

  2. Lagrange's theorem. For any finite group GG and any aGa \in G, the order of aa divides G|G|. So aG=ea^{|G|} = e (identity).

  3. Apply to our group. (Z/nZ)×=φ(n)|(\mathbb{Z}/n\mathbb{Z})^\times| = \varphi(n), so aφ(n)1(modn)a^{\varphi(n)} \equiv 1 \pmod n for any unit aa.

  4. Multiplicativity. For coprime m,nm, n, the Chinese Remainder TheoremChinese Remainder TheoremZ/mnZZ/mZ×Z/nZ\mathbb{Z}/mn\mathbb{Z} \cong \mathbb{Z}/m\mathbb{Z} \times \mathbb{Z}/n\mathbb{Z}Simultaneous congruences with coprime moduli have a unique solution mod their productRead more → gives a ring isomorphism Z/mnZZ/mZ×Z/nZ\mathbb{Z}/mn\mathbb{Z} \cong \mathbb{Z}/m\mathbb{Z} \times \mathbb{Z}/n\mathbb{Z}. Passing to units: φ(mn)=φ(m)φ(n)\varphi(mn) = \varphi(m)\varphi(n).

Connections

Euler's theorem is the engine of RSA encryption: a message MM encrypted as MemodnM^e \bmod n (with gcd(e,φ(n))=1\gcd(e, \varphi(n))=1) is decrypted by CdmodnC^d \bmod n where ed1(modφ(n))ed \equiv 1 \pmod{\varphi(n)} (found via Bezout's IdentityBezout's Identitygcd(a,b)=ax+by\gcd(a,b) = a \cdot x + b \cdot yThe gcd of two integers is always an integer linear combination of those integersRead more →). The special case n=pn=p recovers Fermat's Little TheoremFermat's Little Theoremapa(modp)a^p \equiv a \pmod{p}For prime p, a^p is congruent to a mod pRead more →. The multiplicativity formula uses the Chinese Remainder TheoremChinese Remainder TheoremZ/mnZZ/mZ×Z/nZ\mathbb{Z}/mn\mathbb{Z} \cong \mathbb{Z}/m\mathbb{Z} \times \mathbb{Z}/n\mathbb{Z}Simultaneous congruences with coprime moduli have a unique solution mod their productRead more →. The totient counts units in Z/nZ\mathbb{Z}/n\mathbb{Z}, linking to Wilson's TheoremWilson's Theorem(p1)!1(modp)(p-1)! \equiv -1 \pmod{p}A natural number p > 1 is prime if and only if (p-1)! ≡ -1 mod pRead more → which identifies when this group has product 1-1. Prime counting via the Fundamental Theorem of ArithmeticFundamental Theorem of Arithmeticn=p1a1p2a2pkakn = p_1^{a_1} \cdot p_2^{a_2} \cdots p_k^{a_k}Every integer greater than 1 has a unique prime factorizationRead more → gives the inclusion-exclusion formula for φ\varphi.

Lean4 Proof

/-- **Euler's theorem**: every unit of `ZMod n` raised to the `n.totient`-th
    power equals 1. Mathlib states this as `ZMod.pow_totient`. -/
theorem euler_theorem {n : } (x : (ZMod n)ˣ) : x ^ n.totient = 1 :=
  ZMod.pow_totient x