1.2.5. Euler’s totient function

This section is based on [BUR11, Sec. 7.2, Sec. 7.4].

We aim to extend Fermat’s Little Theorem (Theorem 1.2.3.1) to composite integers with an appropriate reformulation of the statement of the theorem. This requires us to study the following number-theoretic function.

Definition 1.2.5.1.

Let n≥1{n\geq 1} be an integer. We define

S=S⁢(n)≔{a∈ℤ:1≤a≤n⁢ and ⁢gcd⁡(a,n)=1}.S=S(n)\coloneqq\{a\in\mathbb{Z}\colon{1\leq a\leq n\text{ and }\gcd(a,n)=1}\}.

Euler’s totient function is the number-theoretic function

φ:n⟼#⁢S⁢(n).\varphi\colon n\longmapsto\#S(n).
Example 1.2.5.2.

We compute φ⁢(n)\varphi(n) for small values of nn:

nn S⁢(n)S(n) φ⁢(n)\varphi(n)
1 {1}\{1\} 1
2 {1}\{1\} 1
3 {1,2}\{1,2\} 2
4 {1,3}\{1,3\} 2
5 {1,2,3,4}\{1,2,3,4\} 4
6 {1,5}\{1,5\} 2
7 {1,2,3,4,5,6}\{1,2,3,4,5,6\} 6
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

End of Lecture 7

Proposition 1.2.5.3.

Let n≥1{n\geq 1} be an integer. Then

n⁢ is a prime number⟺φ⁢(n)=n−1.n\text{ is a prime number}\quad\Longleftrightarrow\quad\varphi(n)=n-1.
Proof.

Suppose that nn is prime. Then

S={1,2,…,n−1},S=\{1,2,\ldots,n-1\},

and hence φ⁢(n)=n−1{\varphi(n)=n-1}.

Conversely, suppose that φ⁢(n)=n−1{\varphi(n)=n-1}. Since φ⁢(1)=1≠0{\varphi(1)=1\neq 0}, we must have n>1{n>1}. Then

S⊆{1,2,…,n−1}S\subseteq\{1,2,\dots,n-1\}

and, since φ⁢(n)=n−1=#⁢S{\varphi(n)=n-1=\#S}, we must have

S={1,2,…,n−1}.S=\{1,2,\dots,n-1\}.

In particular, for each 1<a<n{1<a<n} we must have

a∤na\nmid n

(as otherwise gcd⁡(a,n)=a≠1{\gcd(a,n)=a\neq 1}). ∎

Lemma 1.2.5.4.

Let n≥1{n\geq 1} be an integer and a,b∈ℤ{a,b\in\mathbb{Z}}. If a≡b(modn){a\equiv b\pmod{n}}, then gcd⁡(a,n)=gcd⁡(b,n){\gcd(a,n)=\gcd(b,n)}.

Proof.

The condition a≡b(modn){a\equiv b\pmod{n}} implies that there exists an integer kk such that b=a−k⁢n{b=a-kn}. By Lemma 1.1.3.1,

gcd⁡(a,n)=gcd⁡(n,a−k⁢n)=gcd⁡(n,b)=gcd⁡(b,n).∎\gcd(a,n)=\gcd(n,a-kn)=\gcd(n,b)=\gcd(b,n).\qed
Theorem 1.2.5.5.

Euler’s totient function φ\varphi is multiplicative.

Proof.

Let m,n≥1{m,n\geq 1} be integers such that gcd⁡(m,n)=1{\gcd(m,n)=1}. We need to prove that φ⁢(m⁢n)=φ⁢(m)⁢φ⁢(n){\varphi(mn)=\varphi(m)\varphi(n)}. Since φ⁢(1)=1{\varphi(1)=1}, the claim is clear if m=1{m=1} or n=1{n=1}.

Suppose that m,n>1{m,n>1}. Arrange the integers 1≤a≤m⁢n{1\leq a\leq mn} as follows:

12⋯r⋯mm+1m+2⋯m+r⋯2⁢m2⁢m+12⁢m+2⋯2⁢m+r⋯3⁢m⋮⋮⋮⋮(n−1)⁢m+1(n−1)⁢m+2⋯(n−1)⁢m+r⋯n⁢m\begin{array}[]{|c|c|c|c|c|c|}1&2&\cdots&r&\cdots&m\\ m+1&m+2&\cdots&m+r&\cdots&2m\\ 2m+1&2m+2&\cdots&2m+r&\cdots&3m\\ \vdots&\vdots&&\vdots&&\vdots\\ (n-1)m+1&(n-1)m+2&\cdots&(n-1)m+r&\cdots&nm\end{array}

Notice that the integers in the rr-th column are congruent to rr modulo mm. We need to compute

φ⁢(m⁢n)\displaystyle\varphi(mn) =#⁢{a∈ℤ:1≤a≤m⁢n⁢ and ⁢gcd⁡(a,m⁢n)=1}\displaystyle=\#\{a\in\mathbb{Z}\colon{1\leq a\leq mn\text{ and }\gcd(a,mn)=1}\}
=#⁢{a∈ℤ:1≤a≤m⁢n,gcd⁡(a,m)=1⁢ and ⁢gcd⁡(a,n)=1}.\displaystyle=\#\{a\in\mathbb{Z}\colon{1\leq a\leq mn,\ \gcd(a,m)=1\text{ and % }\gcd(a,n)=1}\}.

The second equality uses Corollary 1.1.3.16. By definition,

φ⁢(m)=#⁢{r∈ℤ:1≤r≤m⁢ and ⁢gcd⁡(r,m)=1}.\varphi(m)=\#\{r\in\mathbb{Z}\colon{1\leq r\leq m\text{ and }\gcd(r,m)=1}\}.

In addition, Lemma 1.2.5.4 implies that the function k↦gcd⁡(k,m){k\mapsto\gcd(k,m)} is constant on each column of the array. Therefore, to prove that φ⁢(m⁢n)=φ⁢(m)⁢φ⁢(n){\varphi(mn)=\varphi(m)\varphi(n)}, we need to show the following:

For each 1≤r≤m{1\leq r\leq m} such that gcd⁡(r,m)=1{\gcd(r,m)=1}, the rr-th column in the array contains exactly φ⁢(n)\varphi(n) integers ss with gcd⁡(s,n)=1{\gcd(s,n)=1}.

Let 1≤r≤m{1\leq r\leq m}. The rr-th column in the array consists of the integers

r,m+r, 2⁢m+r,…,(n−1)⁢m+r.r,\ m+r,\ 2m+r,\ \ldots,\ (n-1)m+r.

For an integer 0≤a<n{0\leq a<n}, let 0≤xa<n{0\leq x_{a}<n} be the unique integer such that

a⁢m+r≡xa(modn).am+r\equiv x_{a}\pmod{n}.

This defines a function

f:{r,m+r,2⁢m+r,…,(n−1)⁢m+r}\displaystyle f\colon\{r,m+r,2m+r,\ldots,(n-1)m+r\} ⟶{0,1,2,…,n−1}\displaystyle\longrightarrow\{0,1,2,\ldots,n-1\}
a⁢m+r\displaystyle am+r ⟼xa.\displaystyle\longmapsto x_{a}.

We claim that the function ff is bijective. Since the domain and the codomain of ff have the same finite cardinality, it is enough to show that ff is injective. Let 0≤a,b<n{0\leq a,b<n} be such that

a⁢m+r≡b⁢m+r(modn).am+r\equiv bm+r\pmod{n}.

By Proposition 1.2.1.6(4),

a⁢m≡b⁢m(modn).am\equiv bm\pmod{n}.

Using Corollary 1.2.1.9 and the assumption gcd⁡(m,n)=1{\gcd(m,n)=1}, we may cancel mm in the latter congruence to obtain a≡b(modn){a\equiv b\pmod{n}}. Since 0≤a,b<n{0\leq a,b<n} by assumption, we must have a=b{a=b} (Proposition 1.2.1.2). This shows that ff is injective and, as explained above, also surjective.

Finally, Lemma 1.2.5.4 implies that gcd⁡(a⁢m+r,n)=gcd⁡(xa,n){\gcd(am+r,n)=\gcd(x_{a},n)}. Therefore, the function ff restricts to a bijection

f:{a⁢m+r:0≤a<n,gcd⁡(a⁢m+r,n)=1}→{s∈ℤ:0≤s<n,gcd⁡(s,n)=1}.f\colon\{am+r\colon{0\leq a<n,\ \gcd(am+r,n)=1}\}\to\{s\in\mathbb{Z}\colon{0% \leq s<n,\ \gcd(s,n)=1}\}.

Consequently,

φ⁢(n)\displaystyle\varphi(n) =#⁢{s∈ℤ:0≤s<n⁢ and ⁢gcd⁡(s,n)=1}\displaystyle=\#\{s\in\mathbb{Z}\colon{0\leq s<n\text{ and }\gcd(s,n)=1}\}
=#⁢{a⁢m+r:0≤a<n⁢ and ⁢gcd⁡(a⁢m+r,n)=1}.\displaystyle=\#\{am+r\colon{0\leq a<n\text{ and }\gcd(am+r,n)=1}\}.

This finishes the proof. ∎

Theorem 1.2.5.6.

Let n>1{n>1} be an integer with prime factorisation n=p1a1⁢⋯⁢pkak{n=p_{1}^{a_{1}}\cdots p_{k}^{a_{k}}}. Then

φ⁢(n)=∏i=1k(piai−piai−1)=n⁢(∏i=1k(1−1pi)).\varphi(n)=\prod_{i=1}^{k}(p_{i}^{a_{i}}-p_{i}^{a_{i}-1})=n\Big{(}\prod_{i=1}^% {k}\Big{(}1-\frac{1}{p_{i}}\Big{)}\Big{)}.
Proof.

We prove the first equality. By Theorem 1.2.5.5 and Proposition 1.1.5.16, it is enough to prove that φ⁢(pa)=pa−pa−1{\varphi(p^{a})=p^{a}-p^{a-1}} if pp is prime and aa is a positive integer. By definition,

φ⁢(pa)=#⁢{k∈ℤ:1≤k≤pa⁢ and ⁢gcd⁡(k,pa)=1}.\varphi(p^{a})=\#\{k\in\mathbb{Z}\colon{1\leq k\leq p^{a}\text{ and }\gcd(k,p^% {a})=1}\}.

Since every divisor of pap^{a} is a power of pp, it follows that

{k∈ℤ:1≤k≤pa⁢ and ⁢gcd⁡(k,pa)=1}={k∈ℤ:1≤k≤pa,p∤k}.\{k\in\mathbb{Z}\colon{1\leq k\leq p^{a}\text{ and }\gcd(k,p^{a})=1}\}=\{k\in% \mathbb{Z}\colon{1\leq k\leq p^{a},\ p\nmid k}\}.

Finally,

{k∈ℤ:1≤k≤pa,p∤k}=({k∈ℤ:1≤k≤pa}∖{p,2⁢p,3⁢p,…,pa−1⁢p})\{k\in\mathbb{Z}\colon{1\leq k\leq p^{a},\ p\nmid k}\}=(\{k\in\mathbb{Z}\colon% {1\leq k\leq p^{a}}\}\setminus\{p,2p,3p,\dots,p^{a-1}p\})

clearly has cardinality pa−pa−1{p^{a}-p^{a-1}}. This shows that

φ⁢(n)=∏i=1k(piai−piai−1).\varphi(n)=\prod_{i=1}^{k}(p_{i}^{a_{i}}-p_{i}^{a_{i}-1}).

We prove the second equality. We have

n⁢(∏i=1k(1−1pi))\displaystyle n\Big{(}\prod_{i=1}^{k}\Big{(}1-\frac{1}{p_{i}}\Big{)}\Big{)} =(p1a1⁢⋯⁢pkak)⁢(∏i=1k(1−1pi))\displaystyle=(p_{1}^{a_{1}}\cdots p_{k}^{a_{k}})\Big{(}\prod_{i=1}^{k}\Big{(}% 1-\frac{1}{p_{i}}\Big{)}\Big{)}
=∏i=1kpiai⁢(1−1pi)\displaystyle=\prod_{i=1}^{k}p_{i}^{a_{i}}\Big{(}1-\frac{1}{p_{i}}\Big{)}
=∏i=1k(piai−piai−1)\displaystyle=\prod_{i=1}^{k}(p_{i}^{a_{i}}-p_{i}^{a_{i}-1})
=φ⁢(n).\displaystyle=\varphi(n).

In the second equality we simply distributed the prime-power factors of nn in a clever way. This finishes the proof. ∎

Example 1.2.5.2 suggests that φ⁢(n)\varphi(n) is almost always even. The precise statement is the following.

Theorem 1.2.5.7.

Let n>2{n>2} be an integer. Then φ⁢(n)\varphi(n) is even.

Proof.

By Theorem 1.2.5.5, the function φ\varphi is multiplicative. Since n>2{n>2}, it admits an odd prime divisor or it is divisible by 44 (possibly both). Therefore, it is enough to show that φ⁢(pa)\varphi(p^{a}) is even for each prime pp and each positive integer aa such that pa≠2{p^{a}\neq 2} (thus, if p=2{p=2}, then a>1{a>1}). Let p=2{p=2} and a>1{a>1}. Then, using Theorem 1.2.5.6,

φ⁢(2a)=2a⁢(1−12)=2a2=2a−1\varphi(2^{a})=2^{a}\Big{(}1-\frac{1}{2}\Big{)}=\frac{2^{a}}{2}=2^{a-1}

is even (we use a−1>0{a-1>0}). If pp is odd, then

φ⁢(pa)=pa−pa−1=pa−1⁢(p−1)\varphi(p^{a})=p^{a}-p^{a-1}=p^{a-1}(p-1)

is even since p−1{p-1} is even. ∎

Example 1.2.5.8.

Not covered in the lectureLet n=504=23⋅32⋅7{n=504=2^{3}\cdot 3^{2}\cdot 7}. Using Theorem 1.2.5.6, we compute

φ⁢(504)=(23−22)⁢(32−3)⁢(7−1)=4⋅6⋅6=144.\varphi(504)=(2^{3}-2^{2})(3^{2}-3)(7-1)=4\cdot 6\cdot 6=144.

All divisors considered below are assumed to be positive.

Theorem 1.2.5.9 (Gauß).

Let n≥1{n\geq 1} be an integer. Then

n=∑d∣nφ⁢(d).n=\sum_{d\mid n}\varphi(d).
Proof.

The function n↦n{n\mapsto n} is multiplicative. Also, Euler’s totient function φ\varphi is multiplicative by Theorem 1.2.5.5. Hence, by Theorem 1.1.6.10, the function F:n↦∑d∣nφ⁢(d){F\colon n\mapsto\sum_{d\mid n}\varphi(d)} is multiplicative. Therefore, to prove the claim, it is enough to consider the case where n=pa{n=p^{a}} with pp a prime and aa a positive integer. By Corollary 1.1.4.9 and Theorem 1.2.5.6,

F⁢(pa)\displaystyle F(p^{a}) =∑d∣paφ⁢(d)=∑k=0aφ⁢(pk)=1+∑k=1a(pk−pk−1)\displaystyle=\sum_{d\mid p^{a}}\varphi(d)=\sum_{k=0}^{a}\varphi(p^{k})=1+\sum% _{k=1}^{a}(p^{k}-p^{k-1})
=1+(p−1)+(p2−p)+⋯+(pa−pa−1)=pa.\displaystyle=1+(p-1)+(p^{2}-p)+\cdots+(p^{a}-p^{a-1})=p^{a}.

This finishes the proof. ∎

Example 1.2.5.10.

Not covered in the lecture Let n=33=3⋅11{n=33=3\cdot 11}. We have

φ⁢(33)=φ⁢(3)⁢φ⁢(11)=2⋅10=20.\varphi(33)=\varphi(3)\varphi(11)=2\cdot 10=20.

The positive divisors of 3333 are 1,3,11,331,3,11,33. As shown in Gauß’ Totient Identity (Theorem 1.2.5.9),

∑d∣33φ⁢(d)=φ⁢(1)+φ⁢(3)+φ⁢(11)+φ⁢(33)=1+2+10+20=33.\sum_{d\mid 33}\varphi(d)=\varphi(1)+\varphi(3)+\varphi(11)+\varphi(33)=1+2+10% +20=33.

End of Lecture 8

Theorem 1.2.5.11.

Let n>1{n>1} be an integer and

S≔{a∈ℤ:1≤a<n⁢ and ⁢gcd⁡(a,n)=1}.S\coloneqq\{a\in\mathbb{Z}\colon{1\leq a<n\text{ and }\gcd(a,n)=1}\}.

Then

n⋅φ⁢(n)2=∑a∈Sa.\frac{n\cdot\varphi(n)}{2}=\sum_{a\in S}a.
Proof.

Equivalently, we prove that

n⋅φ⁢(n)=2⋅∑a∈Sa.n\cdot\varphi(n)=2\cdot\sum_{a\in S}a.

We claim that

S={n−a:a∈S}.S=\{n-a\colon{a\in S}\}.

Write S={a1,a2,…,aφ⁢(n)}{S=\{a_{1},a_{2},\dots,a_{\varphi(n)}\}}. For each 1≤i≤φ⁢(n){1\leq i\leq\varphi(n)}, the following statements hold:

  • •
    ​

    1≤ai<n{1\leq a_{i}<n} if and only if 1≤n−ai<n{1\leq n-a_{i}<n}.

  • •
    ​

    gcd⁡(ai,n)=1{\gcd(a_{i},n)=1} if and only if gcd⁡(n−ai,n)=1{\gcd(n-a_{i},n)=1} (Lemma 1.1.3.1).

Therefore, the function S→S{S\to S}, a↦n−a{a\mapsto n-a} is well-defined and it is clearly its own inverse:

a⟼n−a⟼n−(n−a)=a.a\longmapsto n-a\longmapsto n-(n-a)=a.

This proves the claim. Finally,

∑a∈Sa=∑a∈S(n−a)=∑a∈Sn−∑a∈Sa=n⋅φ⁢(n)−∑a∈Sa.\sum_{a\in S}a=\sum_{a\in S}(n-a)=\sum_{a\in S}n-\sum_{a\in S}a=n\cdot\varphi(% n)-\sum_{a\in S}a.

Equivalently, n⋅φ⁢(n)=2⋅∑a∈Sa{n\cdot\varphi(n)=2\cdot\sum_{a\in S}a}. ∎

Theorem 1.2.5.12.

Let n≥1{n\geq 1} be an integer. Then

φ⁢(n)=n⁢∑d∣nμ⁢(d)d.\varphi(n)=n\sum_{d\mid n}\frac{\mu(d)}{d}.
Proof.

By Gauß’ Identity (Theorem 1.2.5.9),

F:n⟼∑d∣nφ⁢(d)=n.F\colon n\longmapsto\sum_{d\mid n}\varphi(d)=n.

Applying the Möbius Inversion Formula (Theorem 1.1.6.7) to recover φ⁢(n)\varphi(n), we obtain

φ⁢(n)=∑d∣nμ⁢(d)⁢F⁢(nd)=∑d∣nμ⁢(d)⁢nd=n⁢∑d∣nμ⁢(d)d.∎\varphi(n)=\sum_{d\mid n}\mu(d)F(\tfrac{n}{d})=\sum_{d\mid n}\mu(d)\frac{n}{d}% =n\sum_{d\mid n}\frac{\mu(d)}{d}.\qed
Example 1.2.5.13.

Not covered in the lectureLet n=33=3⋅11{n=33=3\cdot 11}, which has the positive divisors 1,3,11,331,3,11,33. As shown in Example 1.2.5.10, we have φ⁢(33)=20{\varphi(33)=20}. On the other hand, in agreement with Theorem 1.2.5.12,

33⋅(∑d∣nμ⁢(d)d)\displaystyle 33\cdot\Big{(}\sum_{d\mid n}\frac{\mu(d)}{d}\Big{)} =33⋅(μ⁢(1)1+μ⁢(3)3+μ⁢(11)11+μ⁢(33)33)\displaystyle=33\cdot\Big{(}\frac{\mu(1)}{1}+\frac{\mu(3)}{3}+\frac{\mu(11)}{1% 1}+\frac{\mu(33)}{33}\Big{)}
=33⋅1+11⋅(−1)+3⋅(−1)+1⋅1\displaystyle=33\cdot 1+11\cdot(-1)+3\cdot(-1)+1\cdot 1
=33−11−3+1\displaystyle=33-11-3+1
=20.\displaystyle=20.