Chinese Reminder Theorem and Euler's Totient Function
Hao Wu~5 min read
Chinese Remainder Theorem
Theorem (CRT).
If n1,n2,…,nk∈N are pairwise coprime, then for any a1,a2,…,ak∈N, there exists an integer x such that
xxx≡a1(modn1),≡a2(modn2),⋮≡ak(modnk).
Proof One
For each i∈[k], define
Ni=ni∏j=1knj.
Clearly, nj∣Ni for every j=i. Moreover, gcd(Ni,ni)=1.
Hence, there exists Mi∈[1,ni−1] such that
MiNi≡1(modni).
It follows that
aiMiNi≡ai(modni).
Therefore,
x=i=1∑kaiMiNi
is a solution. In fact, for any ℓ∈Z,
x+ℓ⋅i=1∏kni
is also a solution. ∎
Proof Two (More Intuitive)
Consider a simple example with moduli 2 and 3:
mod2mod3000111202310401512⋯⋯⋯
There is a one-to-one correspondence between numbers in {0,1,2,3,4,5} and pairs in {0,1}×{0,1,2}.
In general, if n1,n2,…,nk are pairwise coprime, then for any x,y∈[0,…,−1+∏jnj], if
xxx≡y(modn1),≡y(modn2),⋮≡y(modnk),
then x=y.
To see this, since nj∣(y−x) for all j.
Therefore, y−x is a common multiple of nj,j∈[k].
Consider the set
{z∈N:z is a common multiple of nj,∀j∈k]}.
It is easy to see each element in this set is a multiple of the minimum one in this set, which is the least common multiple of the nj, ∀j∈[k].
Since the nj’s are coprime, it follows that the least common multiple is ∏jnj and
j∏nj∣(y−x).
But since x,y∈[0,…,−1+∏jnj], we must have x=y.
Thus, there is a one-to-one correspondence between [0,…,−1+∏jnj] and the Cartesian product [n1]×[n2]×⋯×[nk].
□
Corollary
There is a unique solution in [0,…,−1+∏jnj].
Proof.
Suppose x and y are two solutions. Then for every i∈[k],
x−y≡0(modni).
Thus, x−y is divisible by ∏i=1kni.
Therefore,
x−y=ℓ⋅i=1∏kni
for some ℓ, so the difference between two solutions is at least ∏i=1kni.
Hence there is exactly one solution modulo ∏i=1kni. ∎
Euler's Totient Function
The Chinese Remainder Theorem has many interesting applications. Here are a few:
Theorem 1.
Let φ(n) denote Euler’s totient function, i.e., the number of integers in [0,…,n−1] that are coprime to n.
If n=pq for primes p and q, then
φ(n)=(p−1)(q−1).
Proof.
By the CRT, there is a one-to-one correspondence between [0,…,n−1] and [0,…,p−1]×[0,…,q−1].
If x∈[0,…,n−1] is not coprime to n, then either p∣x or q∣x.
Thus, x corresponds to a pair of the form (0,a) or (b,0) for some a∈[0,…,q−1], b∈[0,…,p−1].
The number of such pairs is
p+q−1.
Hence,
φ(n)=pq−(p+q−1)=(p−1)(q−1).
∎
Theorem 2.
If n=pq for coprime integers p,q>1, then
φ(n)=φ(p)φ(q).
Proof.
By Chinese Reminder Theorem, there is a one-to-one correspondence between [0,…,n−1] and [0,…,p−1]×[0,…,q−1].
An integer x∈[0,…,n−1] is coprime to n if and only if gcd(x,p)=1 and gcd(x,q)=1.
Thus, x corresponds to a pair (xmodp,xmodq) where each component is coprime to its modulus.
There are φ(p) possibilities for the first component and φ(q) for the second, so
φ(n)=φ(p)φ(q).
∎
Theorem 3.
Let n=p1k1p2k2⋯pmkm be the prime factorization of n. Then