Euler-Totient Function

Euler-φ Function

For n∈Z+, let φ(n) be the number of positive integers a≤n with a relatively prime to n. Namely, (a,n)=1 (so you are counting the "primes" up to n).

For example φ(12)=4 since 1,5,7,11 are the only positive integers less than or equal to 12 with no factor in common with 12. Similarly φ(1)=1,φ(2)=1,φ(3)=2,φ(4)=2,.... For primes p we have φ(p)=p−1 and more generally for all a≥1 we have:

φ(pa)=pa−pa−1=pa−1(p−1)

The function φ is multiplicative in the sense that:

φ(ab)=φ(a)φ(b)⟺gcd(a,b)=1

So for any general n∈N then n=p1α1p2α2…psαs so then:

φ(n)=∏i=1sφ(piαi)=∏piαi−1(pi−1)

For instance φ(12)=φ(22)φ(3)=21(2−1)⋅30(3−1)=4.