Euler's Totient Function

⚡ Key Takeaways

Euler's totient function φ(n)\varphi(n) counts the positive integers up to nn that are coprime to nn. Key result: it is multiplicative, with φ(pk)=pk−pk−1\varphi(p^k) = p^k - p^{k-1}, giving the product formula φ(n)=n∏p∣n(1−1/p)\varphi(n) = n\prod_{p\mid n}(1 - 1/p). Where it applies: number theory, the structure of (Z/nZ)×(\mathbb{Z}/n\mathbb{Z})^\times, RSA cryptography, and Euler's theorem. Who/when: introduced by Leonhard Euler (1763), with the notation φ\varphi standardized by Gauss (1801).

💡 The Core Insight

Counting integers coprime to nn becomes easy when you break nn into its prime-power building blocks. The Chinese Remainder Theorem guarantees that being coprime to n=p1a1⋯prarn = p_1^{a_1}\cdots p_r^{a_r} is equivalent to being simultaneously coprime to each piaip_i^{a_i} independently. This independence makes φ\varphi multiplicative, so the whole function is determined by its values on prime powers, which can be counted directly by subtracting off the multiples of each prime.

Formal Statement

DefinitionEuler's Totient Function

For a positive integer nn, the totient φ(n)\varphi(n) is the number of integers kk with 1≤k≤n1 \le k \le n such that gcd⁡(k,n)=1\gcd(k, n) = 1:

1
φ(n)=#{ k∈Z:1≤k≤n, gcd⁡(k,n)=1 }\quad \varphi(n) = \#\{\, k \in \mathbb{Z} : 1 \le k \le n,\ \gcd(k,n) = 1 \,\}

Derivation hint: This is a direct count; φ(1)=1\varphi(1) = 1 by the convention that gcd⁡(1,1)=1\gcd(1,1)=1, so 11 is counted. Here gcd⁡(k,n)\gcd(k,n) denotes the greatest common divisor of kk and nn. The integers counted are called totatives of nn. Equivalently, φ(n)\varphi(n) is the order (cardinality) of the multiplicative group (Z/nZ)×(\mathbb{Z}/n\mathbb{Z})^\times of residue classes that are invertible modulo nn.

DefinitionMultiplicative Function

An arithmetic function ff is multiplicative if f(mn)=f(m)f(n)f(mn) = f(m)f(n) whenever gcd⁡(m,n)=1\gcd(m,n) = 1, and completely multiplicative if this holds for all m,nm,n. The totient is multiplicative but not completely multiplicative (see the warning below).

TheoremProduct Formula for the Totient

Let n=p1a1p2a2⋯prarn = p_1^{a_1} p_2^{a_2} \cdots p_r^{a_r} be the prime factorization of n>1n > 1, with distinct primes pip_i and exponents ai≥1a_i \ge 1. Then

2
φ(n)=∏i=1r(piai−piai−1)=n∏p∣n(1−1p)\quad \varphi(n) = \prod_{i=1}^{r}\left(p_i^{a_i} - p_i^{a_i - 1}\right) = n \prod_{p \mid n}\left(1 - \frac{1}{p}\right)

Derivation hint: Compute φ\varphi on each prime power, then multiply using multiplicativity; the second form factors piaip_i^{a_i} out of each term. The product ∏p∣n\prod_{p\mid n} runs over the distinct prime divisors of nn only (the exponents do not appear in the second form).

TheoremPrime-Power Value

For a prime pp and integer k≥1k \ge 1,

3
φ(pk)=pk−pk−1=pk−1(p−1)=pk(1−1p)\quad \varphi(p^k) = p^k - p^{k-1} = p^{k-1}(p-1) = p^k\left(1 - \frac{1}{p}\right)

Derivation hint: Among 1,…,pk1,\dots,p^k the integers sharing a factor with pkp^k are exactly the multiples of pp, of which there are pk−1p^{k-1}. In particular φ(p)=p−1\varphi(p) = p - 1 for any prime pp.

TheoremDivisor Sum Identity (Gauss)

For every positive integer nn,

4
∑d∣nφ(d)=n\quad \sum_{d \mid n} \varphi(d) = n

Derivation hint: Partition {1,…,n}\{1,\dots,n\} according to the value of gcd⁡(k,n)=n/d\gcd(k,n)=n/d; each class with that gcd has exactly φ(d)\varphi(d) elements.

TheoremEuler's Theorem

If gcd⁡(a,n)=1\gcd(a,n) = 1, then

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

Derivation hint: The unit aa lives in the group (Z/nZ)×(\mathbb{Z}/n\mathbb{Z})^\times of order φ(n)\varphi(n); Lagrange's theorem forces aφ(n)=ea^{\varphi(n)} = e. This generalizes Fermat's Little Theorem ap−1≡1(modp)a^{p-1}\equiv 1 \pmod p, recovered by setting n=pn = p prime so φ(p)=p−1\varphi(p)=p-1.

Why It Holds / Derivation

ProofMultiplicativity of the Totient

We prove φ(mn)=φ(m)φ(n)\varphi(mn) = \varphi(m)\varphi(n) whenever gcd⁡(m,n)=1\gcd(m,n)=1.

Step 1 — Set up the bijection. By the Chinese Remainder Theorem (CRT), since gcd⁡(m,n)=1\gcd(m,n)=1, there is a ring isomorphism

Z/mnZ  ≅  Z/mZ×Z/nZ,\mathbb{Z}/mn\mathbb{Z} \;\cong\; \mathbb{Z}/m\mathbb{Z} \times \mathbb{Z}/n\mathbb{Z},

sending k  mnk \bmod mn to the pair (k  m, k  n)(k \bmod m,\ k \bmod n).

Step 2 — Units correspond to units. A ring isomorphism maps the group of units of one ring onto the group of units of the other, and units of a product ring are exactly the pairs of units:

(Z/mnZ)×  ≅  (Z/mZ)××(Z/nZ)×.(\mathbb{Z}/mn\mathbb{Z})^\times \;\cong\; (\mathbb{Z}/m\mathbb{Z})^\times \times (\mathbb{Z}/n\mathbb{Z})^\times.

Step 3 — Count both sides. Taking cardinalities, #(Z/mnZ)×=φ(mn)\#(\mathbb{Z}/mn\mathbb{Z})^\times = \varphi(mn), and the product side has φ(m)⋅φ(n)\varphi(m)\cdot\varphi(n) elements. Hence φ(mn)=φ(m)φ(n)\varphi(mn) = \varphi(m)\varphi(n). ■\blacksquare

Step 4 — Derive the product formula. Write n=∏piain = \prod p_i^{a_i}. Repeated application of multiplicativity gives φ(n)=∏φ(piai)\varphi(n) = \prod \varphi(p_i^{a_i}). By equation [3][3], φ(piai)=piai(1−1/pi)\varphi(p_i^{a_i}) = p_i^{a_i}(1 - 1/p_i). Multiplying and collecting the piaip_i^{a_i} into nn yields φ(n)=n∏p∣n(1−1/p)\varphi(n) = n\prod_{p\mid n}(1 - 1/p), which is equation [2][2]. ■\blacksquare

∎
ProofGauss's Divisor Sum Identity

We prove ∑d∣nφ(d)=n\sum_{d\mid n}\varphi(d) = n.

Step 1 — Classify by gcd. Each integer kk in {1,2,…,n}\{1,2,\dots,n\} has a well-defined value g=gcd⁡(k,n)g = \gcd(k,n), which is a divisor of nn. Partition the set into classes Sg={k:gcd⁡(k,n)=g}S_g = \{k : \gcd(k,n) = g\}.

Step 2 — Count one class. Write k=g⋅jk = g\cdot j. Then gcd⁡(k,n)=g\gcd(k,n) = g iff gcd⁡(j,n/g)=1\gcd(j, n/g) = 1, with 1≤j≤n/g1 \le j \le n/g. The number of such jj is exactly φ(n/g)\varphi(n/g).

Step 3 — Sum over classes. The classes partition {1,…,n}\{1,\dots,n\}, so

n=∑g∣n#Sg=∑g∣nφ(n/g).n = \sum_{g \mid n} \#S_g = \sum_{g\mid n} \varphi(n/g).

Step 4 — Reindex. As gg ranges over divisors of nn, so does d=n/gd = n/g. Therefore n=∑d∣nφ(d)n = \sum_{d\mid n}\varphi(d). ■\blacksquare

∎
mathematician · Leonhard Euler | 1707–1783

The Swiss polymath Leonhard Euler introduced the totient function in his 1763 paper Theoremata arithmetica nova methodo demonstrata, where he proved the congruence now bearing his name as a generalization of Fermat's Little Theorem. Euler used the function to extend results about residues to composite moduli, a critical step toward the structure theory of modular arithmetic. He did not use the symbol φ\varphi; he wrote the function descriptively. The notation φ(n)\varphi(n), and the German name Totient, came later—φ\varphi from Carl Friedrich Gauss in the Disquisitiones Arithmeticae (1801), and "totient" coined by J. J. Sylvester. Euler's contributions to number theory, analysis, mechanics, and graph theory make him one of the most prolific mathematicians in history.

Building Intuition

🧠 Intuition

Think of φ(n)\varphi(n) as answering: "Of the residue classes mod nn, how many can be inverted by multiplication?" An element aa has a multiplicative inverse mod nn precisely when gcd⁡(a,n)=1\gcd(a,n)=1—because the equation ax≡1(modn)ax \equiv 1 \pmod n is solvable exactly under that condition (Bézout's identity). So φ(n)\varphi(n) literally counts the "usable" multipliers. The product formula n∏(1−1/p)n\prod(1-1/p) has a probabilistic reading. Pick a random integer near nn; the "chance" it avoids the prime pp as a factor is 1−1/p1 - 1/p. Because divisibility by distinct primes behaves independently, you multiply these chances together, and scaling by nn converts a probability into a count. This independence is exactly what the Chinese Remainder Theorem makes rigorous.

Figure
Totatives of n = 12: integers coprime to 12 are highlighted; the count gives φ(12) = 4
n = 12, prime factors 2 and 3 φ(12) = 12·(1−1/2)·(1−1/3) = 12·(1/2)·(2/3) = 4 1 2 3 4 5 6 7 8 9 10 11 12 Coprime to 12 (gold): {1, 5, 7, 11} → count = 4 Grey: share factor 2 or 3 with 12

Worked Examples

ExampleComputing φ(360) from the Factorization

Given: n=360n = 360. Compute φ(360)\varphi(360).

Step 1 — Factor. 360=23⋅32⋅5360 = 2^3 \cdot 3^2 \cdot 5. The distinct primes are 2,3,52, 3, 5.

Step 2 — Apply the product formula (equation [2][2]):

φ(360)=360(1−12)(1−13)(1−15).\varphi(360) = 360\left(1 - \tfrac12\right)\left(1 - \tfrac13\right)\left(1 - \tfrac15\right).

Step 3 — Evaluate.

φ(360)=360⋅12⋅23⋅45=360⋅830=288030=96.\varphi(360) = 360 \cdot \tfrac12 \cdot \tfrac23 \cdot \tfrac45 = 360 \cdot \tfrac{8}{30} = \tfrac{2880}{30} = 96.

Step 4 — Cross-check via prime powers (equation [3][3]): φ(23)=8−4=4\varphi(2^3)=8-4=4, φ(32)=9−3=6\varphi(3^2)=9-3=6, φ(5)=4\varphi(5)=4; product 4⋅6⋅4=964\cdot 6\cdot 4 = 96. ✓

φ(360)=96 integers in {1,…,360} are coprime to 360\boxed{\varphi(360) = 96 \text{ integers in } \{1,\dots,360\} \text{ are coprime to } 360}
ExampleUsing Euler's Theorem to Reduce a Huge Power

Given: Find the last two digits of 78037^{803}, i.e. compute 7803  1007^{803} \bmod 100.

Step 1 — Set up. Last two digits means working mod 100100. Since gcd⁡(7,100)=1\gcd(7,100)=1, Euler's theorem (equation [5][5]) applies.

Step 2 — Compute the modulus exponent. 100=22⋅52100 = 2^2 \cdot 5^2, so

φ(100)=100(1−12)(1−15)=100⋅12⋅45=40.\varphi(100) = 100\left(1-\tfrac12\right)\left(1-\tfrac15\right) = 100\cdot \tfrac12 \cdot \tfrac45 = 40.

Step 3 — Reduce the exponent mod 40. 803=40⋅20+3803 = 40\cdot 20 + 3, so 7803=(740)20⋅73≡120⋅73(mod100)7^{803} = (7^{40})^{20}\cdot 7^3 \equiv 1^{20}\cdot 7^3 \pmod{100}.

Step 4 — Finish. 73=343≡43(mod100)7^3 = 343 \equiv 43 \pmod{100}.

7803≡43(mod100)  ⇒  last two digits are 43\boxed{7^{803} \equiv 43 \pmod{100} \;\Rightarrow\; \text{last two digits are } 43}

Common Misconceptions

⚠️ Common mistake

The totient is multiplicative, NOT completely multiplicative. The identity φ(mn)=φ(m)φ(n)\varphi(mn)=\varphi(m)\varphi(n) requires gcd⁡(m,n)=1\gcd(m,n)=1. When the arguments share a factor it fails. Likewise, beware these traps:

  • φ(pk)≠(p−1)k\varphi(p^k) \ne (p-1)^k in general; the correct value is pk−1(p−1)p^{k-1}(p-1).
  • In the product formula n∏p∣n(1−1/p)n\prod_{p\mid n}(1-1/p), the product is over distinct primes; do not repeat a prime for higher exponents.
  • φ(n)\varphi(n) is even for all n>2n > 2. There is no nn with φ(n)=14\varphi(n) = 14 (it is not in the image), so not every even number is a totient value—values like 14,26,34,…14, 26, 34, \dots are "nontotients."
CounterexampleFailure of Complete Multiplicativity

Take m=n=6m = n = 6, which are not coprime. Then

φ(6⋅6)=φ(36)=φ(22⋅32)=36⋅12⋅23=12,\varphi(6\cdot 6) = \varphi(36) = \varphi(2^2\cdot 3^2) = 36\cdot\tfrac12\cdot\tfrac23 = 12,

but

φ(6)⋅φ(6)=4⋅4=16≠12.\varphi(6)\cdot\varphi(6) = 4\cdot 4 = 16 \ne 12.

The two disagree precisely because gcd⁡(6,6)=6≠1\gcd(6,6) = 6 \ne 1. A smaller case: φ(4)=2\varphi(4) = 2 while φ(2)φ(2)=1⋅1=1\varphi(2)\varphi(2) = 1\cdot 1 = 1. Multiplicativity simply does not apply to non-coprime arguments.

Connections

connection

The totient sits at the crossroads of several core structures. It is the order of the unit group studied in Modular Arithmetic, so its value governs element orders and the existence of Primitive Roots (which exist mod nn exactly when (Z/nZ)×(\mathbb{Z}/n\mathbb{Z})^\times is cyclic). Equation [4][4] is a special case of Dirichlet Convolution: writing Id=φ∗1\mathrm{Id} = \varphi * \mathbf{1}, Möbius inversion recovers φ=Id∗μ\varphi = \mathrm{Id} * \mu, linking φ\varphi to the Möbius Function. Euler's theorem (equation [5][5]) is a corollary of Lagrange's Theorem (Group Theory) applied to the unit group, and generalizes Fermat's Little Theorem. The summatory behavior of φ\varphi connects to Analytic Number Theory through the asymptotic density of coprime pairs and the Riemann Zeta Function via the Dirichlet series ∑φ(n)n−s=ζ(s−1)/ζ(s)\sum \varphi(n)n^{-s} = \zeta(s-1)/\zeta(s).

Real-World Applications

🔬 Where this appears

Historical Development

⏳ History
- 1640 — Pierre de Fermat states his "Little Theorem" ap−1≡1(modp)a^{p-1}\equiv 1\pmod p, the prime-modulus precursor to Euler's generalization.
- 1736 — Euler publishes the first known proof of Fermat's Little Theorem.
- 1763 — Euler introduces the totient idea and proves aφ(n)≡1(modn)a^{\varphi(n)}\equiv 1\pmod n in Theoremata arithmetica nova methodo demonstrata.
- 1801 — Gauss, in Disquisitiones Arithmeticae, systematizes modular arithmetic, introduces the symbol φ\varphi, and proves the divisor-sum identity ∑d∣nφ(d)=n\sum_{d\mid n}\varphi(d)=n.
- 1832 — Gauss's framework clarifies the structure of (Z/nZ)×(\mathbb{Z}/n\mathbb{Z})^\times and the existence of primitive roots, all phrased through φ\varphi.
- 1879 — J. J. Sylvester coins the term "totient."
- 1932 — Robert Carmichael studies the related λ(n)\lambda(n) (Carmichael function), the exact exponent of the unit group, refining Euler's bound.
- 1962 — Wacław Sierpiński and others investigate the distribution of nontotients and Carmichael's totient-uniqueness conjecture.
- 1977 — Rivest, Shamir, and Adleman base the RSA cryptosystem on φ(pq)\varphi(pq), making the totient a cornerstone of modern security.

Subtleties & Limits

open-problem

Several deep questions about φ\varphi remain unresolved:

  • Carmichael's Totient Conjecture (1907). For every nn, is there always another integer m≠nm \ne n with φ(m)=φ(n)\varphi(m) = \varphi(n)? In other words, no totient value is attained exactly once. It has been verified for nn up to enormous bounds (φ(n)<101010\varphi(n) < 10^{10^{10}}) but no proof exists.
  • Lehmer's Totient Problem (1932). Does φ(n)∣(n−1)\varphi(n) \mid (n-1) ever hold for composite nn? For primes it always holds since φ(p)=p−1\varphi(p)=p-1; whether a composite counterexample exists is unknown. Any such nn must have at least 15 prime factors.
  • Distribution of values. The average order satisfies 1n∑k≤nφ(k)∼3π2n\frac{1}{n}\sum_{k\le n}\varphi(k) \sim \frac{3}{\pi^2}n, but the fine fluctuations and the precise structure of the image (totients vs. nontotients) involve subtle analytic estimates (Ford's theorem, 1998, on the multiplicity of totient values).
  • Iterated totients. The behavior of repeatedly applying φ\varphi (the "totient chain" reaching 11) and its length is studied but not fully understood.

See Also

Fermat's Little Theorem · Carmichael Function · Dirichlet Convolution · Möbius Function · Chinese Remainder Theorem · Primitive Roots · RSA Cryptography · Cyclotomic Polynomials · Analytic Number Theory