What is the Euler Totient Function?
Imagine you have a clock with n hours marked on it. You start at 0 and take steps of size k — that is, you move k hours forward each time. The question is: will you ever hit every single hour on the clock? Or will you get stuck in a loop that visits only some of them?
The answer depends on k and n. If k and n share a common divisor greater than 1, you'll only hit a fraction of the hours. But if k and n are coprime (no common factor except 1), you'll eventually visit every hour. The Euler Totient Function, written ϕ(n), counts exactly how many numbers k in the range 1≤k≤n are coprime to n.
That's the intuition: ϕ(n) tells you how many "step sizes" will let you cycle through all n positions on a clock.
The Precise Definition
For a positive integer n, the Euler Totient Function ϕ(n) is defined as:
ϕ(n)=the number of integers k with 1≤k≤n such that gcd(k,n)=1
Here gcd(k,n) means the greatest common divisor of k and n. When gcd(k,n)=1, we say k and n are coprime or relatively prime.
Examples to Build Feel
- ϕ(1)=1 — by convention, 1 is coprime to itself.
- ϕ(2)=1 — only 1 is coprime to 2.
- ϕ(3)=2 — 1 and 2 are both coprime to 3.
- ϕ(4)=2 — 1 and 3 are coprime to 4; 2 shares a factor of 2.
- ϕ(5)=4 — all numbers 1 through 4 are coprime to 5.
- ϕ(6)=2 — only 1 and 5 are coprime to 6; 2, 3, 4 all share a factor.
Notice a pattern: for a prime p, every number from 1 to p−1 is coprime to p, so ϕ(p)=p−1.
Why It Matters
The totient function is the backbone of Euler's Theorem, which says:
If gcd(a,n)=1, then aϕ(n)≡1(modn).
This result is the engine behind RSA encryption — the system that secures your online banking, messaging apps, and pretty much every password you type on the web. Without ϕ(n), modern cryptography as we know it would not exist.
How to Compute ϕ(n) Quickly
You don't have to list all numbers from 1 to n and check each one. There's a formula based on the prime factorization of n.
If n=p1a1⋅p2a2⋯pkak, where each pi is a distinct prime, then:
ϕ(n)=n(1−p11)(1−p21)⋯(1−pk1)
Example: Compute ϕ(12). Factor 12=22⋅3. Then:
ϕ(12)=12(1−21)(1−31)=12⋅21⋅32=4 …