Chinese Remainder Theorem
Ever faced a puzzle that felt like juggling multiple clues at once? The Chinese Remainder Theorem is a powerful mathematical tool for solving exactly that kind of problem. It helps you find a single number that satisfies several different remainder conditions simultaneously, a skill with surprising applications.

What Is the Chinese Remainder Theorem?
The Chinese Remainder Theorem (CRT) is a principle from number theory that provides a way to find a unique solution to a system of simultaneous congruences, as long as their moduli are pairwise coprime. In simple terms, it's a method for finding a number that leaves specific remainders when divided by several different numbers.
Imagine you have a big bag of marbles. You don't know the total, but you know a few clues:
- When you group the marbles into sets of 3, you have 2 left over.
- When you group them into sets of 5, you have 3 left over.
- When you group them into sets of 7, you have 2 left over.
How can you find the smallest possible number of marbles in the bag? This is exactly the kind of puzzle the Chinese Remainder Theorem was designed to solve. It takes multiple 'remainder' clues and combines them to find the single number that makes them all true.
What Are Congruences? A Quick Refresher
Before we can use the theorem, we need to be comfortable with the language it uses: congruences and modular arithmetic. You can think of modular arithmetic as "clock arithmetic." On a 12-hour clock, 15 hours after midnight is 3 o'clock. We can say that 15 is congruent to 3, modulo 12.
The notation we use is:
This means that
The Chinese Remainder Theorem solves a system of these congruences. A typical problem looks like this, where you need to find the unknown number
There's one very important condition for the standard theorem to work: the moduli (the numbers you're dividing by,
How Does the Theorem Work with a Simple Case?
Let's build our intuition with a basic two-line problem. We want to find a number
Since the numbers are small, we can just list out possibilities for each line and see where they overlap.
- Numbers that satisfy
: 2, 5, 8, 11, 14, 17, ... (these are all 2 more than a multiple of 3). - Numbers that satisfy
: 1, 5, 9, 13, 17, 21, ... (these are all 1 more than a multiple of 4).
Looking at our lists, we can see that 5 is the first number to appear in both. So,
Find the smallest positive integer
Solution by listing:
- List numbers for the first congruence: The numbers that leave a remainder of 2 when divided by 3 are 2, 5, 8, 11, ...
- Check these numbers against the second congruence:
- Does 2 work?
has a remainder of 2. No, we need a remainder of 1. - Does 5 work?
has a remainder of 1. Yes!
The smallest positive integer solution is
This listing method is great for simple problems, but it quickly becomes impractical for larger numbers. For that, we need a systematic algorithm.
What Are the Steps to Solve Any System of Congruences?
Here is a reliable, step-by-step method to solve any system of congruences that meets the coprime condition. Let's use the general form from before:
- Step 1: Check the Condition. Verify that all the moduli (
) are pairwise coprime. If they aren't, this method won't work. - Step 2: Calculate the Big Modulus (N). Multiply all the individual moduli together to get one large product,
. This is the number after which the solutions will repeat. - Step 3: Calculate Partial Products (N_i). For each congruence
, calculate . In other words, is the product of all moduli except for . - Step 4: Find the Modular Inverses (y_i). This is the most clever step. For each
, you need to find a number that solves the congruence: This is called the modular multiplicative inverse of modulo . For small numbers, you can find this by testing values for : 1, 2, 3, ... until you find one that works. - Step 5: Assemble the Solution (x_0). Now, you combine all the pieces you've found using one main formula. You multiply each remainder (
), its partial product ( ), and its inverse ( ) together, and then sum up all these results. - Step 6: Find the Smallest Positive Solution. The number
from Step 5 is a valid solution, but it might be very large. The general solution is any number congruent to modulo . To find the smallest positive solution, you simply calculate the remainder of when divided by . This final remainder is your answer.
A Fully Worked Example: Putting the Steps into Practice
Let's solve the marble problem from the introduction. We need to find the smallest positive integer
Solve the system of congruences above using the 6-step method.
Solution:
Step 1: Check the Condition. Our moduli are 3, 5, and 7. Since these are all prime numbers, they are automatically pairwise coprime. Check: GCD(3,5)=1, GCD(3,7)=1, GCD(5,7)=1. We can proceed.
Step 2: Calculate N.
Step 3: Calculate N_i.
- For
: . - For
: . - For
: .
Step 4: Find Inverses y_i.
- For
: We need to solve . First, simplify . , so the remainder is 2. The congruence becomes . Let's test values: If , we get . If , we get , and . Perfect! So, . - For
: We need . Simplify . The remainder is 1. The congruence is . This is easy: . - For
: We need . Simplify . The remainder is 1. The congruence is . So, .
Let's organize our findings in a table:
| i | ||||
|---|---|---|---|---|
| 1 | 2 | 3 | 35 | 2 |
| 2 | 3 | 5 | 21 | 1 |
| 3 | 2 | 7 | 15 | 1 |
Step 5: Assemble the Solution. Using the formula
Step 6: Find the Smallest Positive Solution. We find the remainder of
The smallest number of marbles in the bag is 23.

How to Solve an Ancient Word Problem with the CRT
The theorem gets its name from early appearances in Chinese mathematical texts. Here is a classic problem, paraphrased from the work of the mathematician Sun Tzu.
An army has an unknown number of soldiers. When the general arranges them in columns of 3, there are 2 soldiers left over. When arranged in columns of 5, there are 3 left over. When arranged in columns of 7, there are 2 left over. What is the smallest possible number of soldiers in the army?
Wait, this is the same problem as the marbles! Yes, it is. The underlying math is identical. Let's try a different one.
New Problem: Find the smallest positive integer that leaves a remainder of 1 when divided by 2, 3, and 5, but is perfectly divisible by 7.
Solution:
First, translate the word problem into a system of congruences:
Step 1: Check Condition. The moduli are 2, 3, 5, and 7. All are prime numbers, so they are pairwise coprime.
Step 2: Calculate N.
Step 3: Calculate N_i.
Step 4: Find Inverses y_i.
- 105y_1 \equiv 1 \pmod{2} \implies 1y_1 \equiv 1 \pmod{2} \implies y_1=1
- 70y_2 \equiv 1 \pmod{3} \implies 1y_2 \equiv 1 \pmod{3} \implies y_2=1
- 42y_3 \equiv 1 \pmod{5} \implies 2y_3 \equiv 1 \pmod{5} \implies y_3=3 (since
) - 30y_4 \equiv 1 \pmod{7} \implies 2y_4 \equiv 1 \pmod{7} \implies y_4=4 (since
)
Step 5: Assemble the Solution.
Step 6: Find the Smallest Positive Solution.
The smallest such integer is 91. Let's check: 91 divided by 2, 3, or 5 leaves a remainder of 1. And
What Are Common Mistakes to Avoid?
The Chinese Remainder Theorem is a powerful algorithm, but it has several steps where it's easy to make a small error. Here are the most common pitfalls to watch out for:
- Forgetting the Coprime Check. The very first step is crucial. If you try to apply this method when the moduli are not pairwise coprime (e.g., trying to solve a system with
and ), you will not get a correct answer. A solution might not even exist. - Mixing Up
and . Remember, is the original modulus from the problem statement. is the value you calculate by dividing the total product by . Keep your work organized in a table to avoid confusion. - Errors Finding the Inverse. Finding
such that can be tricky. Always double-check your inverse by multiplying it out. For example, in the last problem we found for . Check: . Is ? Yes, because 126 ends in a 6, so its remainder when divided by 5 is 1. - Forgetting the Final Modulo Step. The formula in Step 5 gives you a solution, but not necessarily the smallest positive one. Forgetting to calculate
at the end is a very common mistake. - Simple Calculation Errors. There are many multiplications and additions involved. Take your time, write out each step, and use a calculator to check your arithmetic, especially for the large sum in Step 5.
Quick Summary and Reference
Here's a quick summary of the entire process for solving a system of congruences using the Chinese Remainder Theorem.
The Goal: Solve a system of congruences:
The Condition: All moduli,
The Algorithm:
- Calculate the total product of the moduli:
. - For each congruence, calculate the partial product:
. - For each congruence, find the modular inverse
that solves . - Calculate the preliminary solution,
, using the main formula: - Find the smallest positive solution,
, by taking the result modulo : .
Frequently Asked Questions
What is the Chinese Remainder Theorem actually used for in the real world?
It's crucial in modern cryptography, especially in the RSA algorithm, for speeding up complex calculations with large numbers. It's also used in computer science for algorithms that handle huge integers and in coding theory for creating error-correcting codes.
What happens if the moduli are not coprime?
The standard theorem doesn't apply directly, but a solution might still exist. You have to use a more advanced, generalized version of the theorem that first checks for contradictions between the congruences (for example,
Where does the name 'Chinese Remainder Theorem' come from?
The earliest known statement of this type of problem appeared in the 3rd-century book 'Sunzi Suanjing' (The Mathematical Classic of Sun Zi) by the Chinese mathematician Sun Tzu. The full algorithm for solving it was later generalized by other mathematicians.
Is the solution always a single number?
The solution is a whole family of numbers. The theorem gives you the unique smallest positive solution, but any number you get by adding or subtracting multiples of the big modulus
What does 'pairwise coprime' mean again?
It means if you take any two different moduli from your list, their greatest common divisor is 1. For example, in the set {6, 7, 25}, they are pairwise coprime because GCD(6,7)=1, GCD(6,25)=1, and GCD(7,25)=1.
Is there an easier way to find the modular inverse?
For the small numbers you see in class, trial and error (testing y=1, 2, 3...) is often the fastest way. For larger numbers, there is a more systematic method called the Extended Euclidean Algorithm, which is a topic you might learn in a more advanced number theory or discrete math class.
Can I solve these problems by just listing out multiples?
Yes, for very small numbers, that can be a good way to understand the problem and find the answer. However, the CRT provides a systematic method that works for any numbers, no matter how large, which is much more powerful and efficient than guessing or listing.