Module 3.2 · Number Theory
The Chinese remainder theorem
The Chinese remainder theorem (CRT) says that knowing a number mod and mod is the same as knowing it mod . That turns one hard modulus into several easy ones. On the AIME, where every answer is a remainder mod in disguise, this is one of the most-used tools you have.
The theorem
Chinese remainder theorem
If are pairwise relatively prime and , then for any remainders the system
has a solution, and the solution is unique mod .
Why it's true (two moduli). Take with and look at the numbers . Send each to its pair of remainders .
- Different give different pairs. If and give the same pair, then and , so (because are coprime). Since , .
- Every pair is hit. There are inputs, all giving different pairs, and exactly possible pairs.
So each pair of remainders corresponds to exactly one residue mod . For more moduli, apply this repeatedly.
A constructive version. By Bézout, there are integers with . Then works: mod it is (since ), and mod it is .
Solving systems in practice
On a contest you rarely need Bézout. Two faster methods:
- Sieve. List numbers satisfying the congruence with the largest modulus, and test them against the next one. Once you find a match, step by the product of the moduli so far.
- Substitute. From write , plug into the next congruence, and solve for .
Common mistake
CRT needs pairwise coprime moduli. If they share a factor, the system might have no solution: and is impossible, since the first says is odd and the second says is even. When the moduli share , a solution exists exactly when , and then it is unique mod , not mod .
Counting with CRT
CRT also counts. If is a polynomial with integer coefficients, then exactly when and . So
For example, has solutions mod (every odd ) and mod (), so solutions mod .
Worked examples
Worked example: A basic system
Find the smallest positive with , , .
Numbers : The first that is is . So . Check mod : . It already works, so .
Worked example: Splitting 1000
Find the last three digits of .
Mod : . Mod : by Euler, since .
Now find with : try . Only is divisible by . The last three digits are .
Worked example: Consecutive numbers
Find the smallest positive such that , and .
The conditions are , , .
Numbers : Those also : is the first, so . Now test mod (digit sums so remainders ): the sixth one, , works.
Check: , , . So .
Worked example: Moduli that aren't coprime
Solve and .
Here . The system is consistent because . The solution is unique mod . Numbers below : . Only is . So .
Tip
When a remainder condition looks like " is divisible by ", rewrite it as modulo the lcm. Negative remainders often make systems collapse into one congruence.
Practice
Find the smallest positive integer that leaves remainder when divided by , remainder when divided by , and remainder when divided by .
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
How many integers with satisfy , and ?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Find the remainder when is divided by .
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
A treasure chest holds fewer than coins. When the coins are split evenly among pirates, are left over; among pirates, are left over; among pirates, are left over. How many coins are in the chest?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
How many positive integers satisfy both and ?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
How many integers with satisfy ?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Find the smallest positive integer such that is divisible by .
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Find the remainder when the product of all odd numbers from to is divided by .
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Real contest practice
- 2011 AIME I, Problem 11: the set of remainders of powers of mod , analyzed mod and mod .
- 2021 AIME II, Problem 13: a condition mod split into conditions mod and mod .