Chinese Remainder Theorem (original) (raw)

Last Updated : 5 Dec, 2025

Chinese Remainder Theorem is a mathematical principle that solves systems of modular equations by finding a unique solution from the remainder of the division. It is used in cryptography and computer science for efficient computation.

According to the Theorem, if in a given set of equations, each equation has a different number (say, n1, n2, ..., nk), and these numbers are all relatively prime to each other, and also have some numbers (say, a1, a2,..., ak), then there is a unique solution (let's call it x) that satisfies all the equations at once.

This solution is found modulo the product of all the numbers (N = n1 · n2 ·...· nk). Therefore, x satisfies each equation by leaving the same remainder when divided by its corresponding number (ni) as the given number (ai).

In simpler terms, the theorem states:

"If a number is divided by several other numbers that have no common factors, one can find the remainder when dividing by the product of those numbers."

The solution is unique modulo **N, meaning any other solution is congruent to the original one modulo **N.

Statement of Chinese Remainder Theorem

The Chinese Remainder Theorem states that a system of simultaneous congruences, defined by pairwise coprime positive integers ****(n** 1 , n 2 ,...., n k ****)** and arbitrary integers ****(a** 1 , a 2 ,...., a k ****)** such as:

**x ≡ a 1 ****(mod n** 1 )

**x ≡ a 2 (mod n 2 )

**

**x ≡ a k (mod n k )

there exists a unique solution x modulo (N = n1 n2 .... nk) that satisfies all the congruances simultaneously.

Chinese Remainder Theorem Proof

To prove Chinese remainder theorem, let us find an integer (x) that satisfies: x ≡ ai (mod ni) for each (i = 1, 2,...., k).

We define (Ni = N/ni).

Since (ni) and (Ni) are coprime, according to **Bézout's identity, there are integers (si) and (ti) such that:

si·ni + ti·Ni = 1

We set (yi = ti·Ni)

Now, let's construct (x) as follows,

x = \sum_{i=1}^k a_i \cdot y_i

This solution satisfies all the congruences, i.e., x ≡ ai (mod ni) for each (i). To see this, observe:

x ≡ ai·yi ≡ ai·ti·Ni ≡ ai·1 ≡ ai

Thus, (x) is a solution to the system of congruences.

**Uniqueness:

Suppose (x) and (x') are two solutions to the system of congruences. We aim to show that (x ≡ x' (mod N).

Let (m = x' - x). Since both (x) and (x') satisfy all the congruences, (m) must also satisfy them. Therefore, (m) is divisible by each of the moduli (n1, n2,...., nk).

By definition, (N = n1 · n2 ·....· nk). As (m) is divisible by each (ni), it is also divisible by (N), i.e., m ≡ 0 (mod N).

Hence, x ≡ x' (mod N, establishing uniqueness).

Necessary Condition for Chinese Remainder Theorem

For the Chinese Remainder Theorem to work, the numbers we are dividing by must not have any common factors. So, if there are two numbers that are being divided by, say (mi) and (mj), then they can not common factors other than 1. That means their biggest shared factor, called the greatest common divisor is 1.

**GCD(m i , m j ) = 1

This condition ensures that the system of congruences is consistent and that the solution provided by the Chinese Remainder Theorem is unique modulo the product of the moduli. If the moduli are not pairwise coprime, then the theorem may not yield a solution, or the solution may not be unique. Therefore, pairwise coprimality is a fundamental requirement for the application of the Chinese Remainder Theorem.

Chinese Remainder Theorem Solution for Two Moduli

Chinese Remainder Theorem provides a solution for systems of congruences involving two moduli. Given two pairwise coprime moduli (m1) and (m2), and their respective residues (a1) and (a2), the theorem states that there exists a unique solution modulo (m1 × m2) for the system of congruences:
x ≠ a1 mod m1

x ≠ a2 mod m2

The solution can be found using the formula:

x = a_1 + m_1 \left( \frac{{a_2 - a_1}}{{m_1}} \right) \left( \frac{{m_1^{-1}}}{{m_2}} \right) \ (\text{mod}\ (m_1 \times m_2))

Where (m1-1) denotes the modular multiplicative inverse of (m1) modulo (m2). This inverse can be found using methods such as the Extended Euclidean Algorithm.

**Extended Euclidean Algorithm****:** Computes the gcd of two integers a and b, along with integers x and y(called Bézout coefficients) such that: a⋅x+b⋅y=gcd⁡(a,b). where,

It is widely used to find modular inverses (critical in cryptography).

Chinese Remainder Theorem Solution for General Case

Chinese Remainder Theorem (CRT) provides a solution for a system of congruences with arbitrary moduli. Suppose we have a system of congruences:

x \equiv a_1 \ (\text{mod}\ m_1)

x \equiv a_2 \ (\text{mod}\ m_2)

x \equiv a_n \ (\text{mod}\ m_n)

Where (m1, m2, ..., mn) are pairwise coprime moduli and (a1, a2, ..., an) are the corresponding residues.

CRT states that there exists a unique solution modulo (M = m1 × m2 × ... × mn) for this system of congruences. The solution can be found using the formula:

x \equiv \sum_{i=1}^{n} a_i M_i y_i \ (\text{mod}\ M)

Where (Mi = M / mi) and (yi) is the modular multiplicative inverse of (Mi) modulo (mi).

Suppose we have the following system of congruences:

x ≡ 2 mod 3

x ≡ 3 mod 5

x ≡ 2 mod 7

Calculate M = 3 × 5 × 7 = 105

Then, we calculate (M1 = 105 / 3 = 35), (M2 = 105 / 5 = 21), and (M3 = 105 / 7 = 15).

find the modular multiplicative inverses (y1), (y2), and (y3) for (M1), (M2), and (M3) modulo (m1), (m2), and (m3), respectively

y1 is the modular multiplicative inverse of 35 modulo 3, which is 2

y2 is the modular multiplicative inverse of 21 modulo 5, which is 1

y3 is the modular multiplicative inverse of 15 modulo 7, which is 1

Now, using the formula:

x ≡ 2 × 35 × 2 + 3 × 21 × 1 + 2 × 15 × 1 (mod 105)

x ≡ 140 + 63 + 30 mod 105)

x ≡ 233 mod 105)

So, the solution for the system of congruences is x ≡ 233 (mod 105)

Chinese Remainder Theorem Solution for Not Coprime Moduli

Chinese Remainder Theorem helps in solving systems of equations where the remainders are congruent, even if the numbers that are divisible by are not relatively prime. But when the divisors are not relatively prime, there might be more than one solution to the problem.

Suppose we have the following system of congruences:

x ≡ 2 (mod 4)

x ≡ 6 (mod 6)

Here, the moduli 4 and 6 are not coprime because their greatest common divisor (GCD) is 2

To find the solution using the Chinese Remainder Theorem, we proceed as follows:

**1. Find the moduli product: Calculate (m = 4 × 6 = 24).

**2. Find the residues: Divide each modulus by the product of the other moduli to find the residue:

In this case, (k = 1) and (k' = 1) satisfy the congruences, so the residues are both 1

**3. Calculate the solution: The solution (x) is given by: x = a1 × m2 × k + a2 × m1 × k' (mod m)

Plugging in the values:

So, the solution for this system of congruences is x ≡ 12 (mod 24).

Also Check:

Application of Chinese Remainder Theorem in Computer Science

Applications of the Chinese remainder theorem are as follows:

**Cryptography

**Error correction

Parallel Computing

Quantum Computing

Algorithmic Optimizations

**Solved Example on Chinese Remainder Theorem

**Suppose a certain number leaves a remainder of 2 when divided by 3, a remainder of 3 when divided by 5, and a remainder of 2 when divided by 7. Find the smallest positive integer that satisfies these conditions using the Chinese Remainder Theorem.

**Solution:

Let _x be the number that satisfies all the given conditions:

Now, as per the Chinese Remainder Theorem, since the moduli (3, 5, and 7) are pairwise coprime, a unique solution modulo is lcm(3,5,7)=105

The modular inverses for each modulus will be:

Now calculate for _x:

_x ≡ (2⋅35⋅2)⋅(2⋅3) + (3⋅3⋅7⋅1) + (2⋅3⋅5)⋅(1⋅1)...(mod 105)

On solving each term we get,

_x ≡ 140 + 63 + 30(mod105)

_x ≡ 233(mod105)

_x ≡ 23(mod105)

∴ Smallest positive integer that satisfies the given conditions is __x_=23.

Practice Questions on Chinese Remainder Theorem

**Question 1: Solve the system of congruences:

x ≡ 2 (mod 3)
x ≡ 3 (mod 5)
x ≡ 2 (mod 7)

**Question 2: Solve the system of congruences:

x ≡ 1 (mod 2)
x ≡ 2 (mod 4)
x ≡ 3 (mod 5)

**Answer Key

  1. **x **= 23 (modulo 105).
  2. There is no solution for this system of congruences, because x ≡ 1 (mod2) (odd) and x ≡ 2 (mod4) (even) are contradictory.