Folioby Interconnected
Log InSign Up

The Chinese Remainder Theorem and Its Applications — Systems of Congruences and Direct Products of Rings

We prove the Chinese remainder theorem as a ring isomorphism. We extend the result to the case where the moduli are not pairwise coprime, present Garner's algorithm, give a CRT-based proof of the multiplicativity of phi, and discuss applications in competitive programming.

FO
Folio Official
March 1, 2026

1 Statement of the Chinese Remainder Theorem

Theorem 1 (Chinese remainder theorem (CRT)).
Let m1​,m2​,…,mk​ be pairwise coprime positive integers (gcd(mi​,mj​)=1 for i=j). Then the system of congruences
x≡a1​(modm1​),x≡a2​(modm2​),…,x≡ak​(modmk​)
has a unique solution modulo M=m1​m2​⋯mk​.
Proof.
Existence. For each i, set Mi​=M/mi​. Since gcd(mi​,mj​)=1 for j=i, we have gcd(Mi​,mi​)=1, so by Béti​ with Mi​ti​≡1(modmi​). Put ei​=Mi​ti​. Then ei​≡1(modmi​) and, for j=i, mj​∣Mi​ gives ei​≡0(modmj​). Setting x=∑i=1k​ai​ei​, we find x≡ai​⋅1+∑j=i​aj​⋅0=ai​(modmi​) for each i.

Uniqueness. If x1​,x2​ are both solutions, then mi​∣(x1​−x2​) for every i. Since the mi​ are pairwise coprime, M=m1​m2​⋯mk​∣(x1​−x2​), i.e. x1​≡x2​(modM). □

2 Algebraic Proof: The Ring Isomorphism

Theorem 2 (Ring-theoretic formulation of CRT).
If m1​,…,mk​ are pairwise coprime and M=m1​⋯mk​, then the map
Φ:Z/MZ∼​Z/m1​Z×Z/m2​Z×⋯×Z/mk​Z
defined by Φ(xˉ)=(xˉ1​,…,xˉk​), where xˉi​=xmodmi​, is a ring isomorphism.
Proof.
That Φ is a ring homomorphism is clear (it preserves sums and products).

Injectivity. If Φ(xˉ)=0ˉ, then mi​∣x for all i. Since the mi​ are pairwise coprime, M∣x, so xˉ=0ˉ in Z/MZ.

Surjectivity. Set Mi​=M/mi​. Since gcd(Mi​,mi​)=1, there exists ti​ with Mi​ti​≡1(modmi​). Put ei​=Mi​ti​. Then ei​≡1(modmi​) and ei​≡0(modmj​) for j=i. For any (a1​,…,ak​), the element x=∑i=1k​ai​ei​ satisfies Φ(xˉ)=(aˉ1​,…,aˉk​).

Since Φ is an injective map between finite sets of the same cardinality (∣Z/MZ∣=M=∏mi​), it is also surjective, hence bijective. □

3 Explicit Construction of Solutions

Example 3.
Solve x≡2(mod3), x≡3(mod5), x≡2(mod7). Here M=105, M1​=35, M2​=21, M3​=15. From 35t1​≡1(mod3) we get t1​=2. From 21t2​≡1(mod5) we get t2​=1. From 15t3​≡1(mod7) we get t3​=1. Therefore x≡2⋅70+3⋅21+2⋅15=233≡23(mod105).

4 The General Case

Theorem 4.
The system x≡a1​(modm1​), x≡a2​(modm2​) has a solution if and only if gcd(m1​,m2​)∣(a1​−a2​). When a solution exists, it is unique modulo lcm(m1​,m2​).
Proof.
Writing x=a1​+m1​k, the second congruence becomes m1​k≡a2​−a1​(modm2​). By the solvability criterion for linear congruences, this has a solution if and only if gcd(m1​,m2​)∣(a2​−a1​). The solution is then unique modulo m1​⋅m2​/gcd(m1​,m2​)=lcm(m1​,m2​). □

5 Garner's Algorithm

Remark 5.
Garner's algorithm expresses the CRT solution in a mixed-radix representation x=r1​+r2​m1​+r3​m1​m2​+⋯, thereby avoiding arithmetic with the (potentially very large) product M. The coefficients ri​ are computed sequentially: r1​=a1​modm1​, r2​=(a2​−r1​)⋅m1−1​modm2​, and so forth. Since every step involves only arithmetic modulo mi​, the algorithm avoids multi-precision multiplication and is highly efficient.

6 Multiplicativity ofφvia CRT

Corollary 6.
If gcd(m,n)=1, then φ(mn)=φ(m)φ(n).
Proof.
Taking the groups of units in the ring isomorphism Z/mnZ≅Z/mZ×Z/nZ gives (Z/mnZ)∗≅(Z/mZ)∗×(Z/nZ)∗. Comparing cardinalities yields φ(mn)=φ(m)φ(n). □
Remark 7.
The CRT is also a fundamental tool in competitive programming. By performing computations modulo several distinct primes p1​,…,pk​ and then combining the results via CRT, one can recover exact values of large quantities or carry out modular arithmetic with respect to a product M.
Number TheoryAlgebraTextbookChinese Remainder TheoremCRT
FO
Folio Official

Mathematics "between the lines" — exploring the intuition textbooks leave out, written in LaTeX on Folio.

1 followers·107 articles
Number Theory TextbookPart 7 of 13
Previous
Primitive Roots and Discrete Logarithms — $(\mathbb{Z}/p\mathbb{Z})^*$ as a Cyclic Group
Next
Quadratic Residues and the Law of Reciprocity — The Theory of Quadratic Residues

Share your expertise with the world

Write articles with LaTeX support, build your audience, and earn from your knowledge.

Start Writing — It's Free

More from Folio Official

Folio Official·March 1, 2026

Continued Fractions and Diophantine Approximation — The Theory of Rational Approximation

We define finite and infinite continued fractions, prove convergence, and rigorously establish the properties of convergents. We develop the theory of best rational approximations, solve the Pell equation x^2 - Dy^2 = 1 via continued fractions, and discuss the Stern--Brocot tree.

Number TheoryAlgebraTextbook
3
Folio Official·March 1, 2026

Primes and the Fundamental Theorem of Arithmetic — The Atomic Decomposition of Integers

We define prime numbers and establish their basic properties, including Euclid's proof of the infinitude of primes. We then give a rigorous proof of the fundamental theorem of arithmetic (existence and uniqueness of prime factorization), and discuss the sieve of Eratosthenes and the Miller--Rabin primality test.

Number TheoryAlgebraTextbook
3
Folio Official·March 1, 2026

Introduction to Algebraic Integers — Extending the Notion of Integer

Using the Gaussian integers Z[i] and the Eisenstein integers Z[omega] as concrete examples, we introduce rings of algebraic integers. We demonstrate the failure of unique factorization in Z[sqrt(-5)] and show how ideals and prime ideal factorization restore uniqueness. We define the class number and discuss its significance.

Number TheoryAlgebraTextbook
2
Folio Official·March 1, 2026

Arithmetic Functions and Multiplicative Functions — Functions on the Integers

We systematically define the principal multiplicative functions (phi, sigma, mu, d), develop the ring structure of Dirichlet convolution, and give a rigorous proof of the Moebius inversion formula. We also clarify the connection to the inclusion-exclusion principle.

Number TheoryAlgebraTextbook
1