Maths in Real Life

The Chinese Remainder Theorem: Solve Remainder Puzzles Step by Step

EuclidCurve Smart Team · 2026-11-13 · 8 min read

For young mathematicians in the UK, USA, UAE, Singapore and Hong Kong

More than 1,500 years ago the Chinese mathematician Sunzi wrote a puzzle in his book Sunzi Suanjing: "There are things whose number is unknown. Counted by threes, two are left; counted by fives, three are left; counted by sevens, two are left. How many things are there?" The method behind the answer is now called the Chinese Remainder Theorem (CRT), and it is a favourite of AMC problem writers.

Guess first: What is the smallest number that solves Sunzi's puzzle?

  • 23
  • 8
  • 52

23 = 3 × 7 + 2 = 5 × 4 + 3 = 7 × 3 + 2. The next solutions are 23 + 105 = 128, 233, and so on, every 105.

The theorem

If the moduli m_1, m_2, …, m_k are pairwise coprime, then the system x \equiv a_1 \pmodm_1, …, x \equiv a_k \pmodm_k always has a solution, and it is unique modulo the product M = m_1 m_2 \cdots m_k. In Sunzi's puzzle M = 3 × 5 × 7 = 105, so there is exactly one answer from 0 to 104.

The sieve method

Take two congruences at a time. List the numbers that fit the larger modulus and test them against the smaller one. For x \equiv 2 \pmod 3 and x \equiv 2 \pmod 7, both say "2 more than a multiple", so x \equiv 2 \pmod21: 2, 23, 44, …. Now test mod 5: 2 gives remainder 2, but 23 gives 3. Done: x = 23.

Your turn

Find the smallest positive x with x \equiv 1 \pmod 4 and x \equiv 2 \pmod 5.

Solution: Of 2, 7, 12, 17, only 17 = 4 × 4 + 1 leaves remainder 1 mod 4. So x \equiv 17 \pmod20.

When the moduli share a factor

If the moduli are not coprime, the congruences must agree on their common part. The system x \equiv a \pmod m, x \equiv b \pmod n has a solution exactly when \gcd(m, n) divides a - b, and then the solution is unique modulo lcm(m, n). For instance x \equiv 1 \pmod 4 and x \equiv 2 \pmod 6 is impossible: the first makes x odd, the second makes it even.

Your turn

Find the smallest positive x with x \equiv 3 \pmod 8 and x \equiv 7 \pmod12.

Solution: Numbers \equiv 7 \pmod12: 7, 19. 7 \equiv 7 \pmod 8 fails, 19 = 2 × 8 + 3 works. So x = 19.

A shortcut for huge powers

The CRT lets you split a hard modulus into easy ones. For the last two digits of 3^2026, work mod 4 and mod 25. Mod 4, 3 \equiv -1 and the power is even, so the answer is 1. Mod 25, 3^20 \equiv 1 (Euler) and 2026 \equiv 6 \pmod20, so 3^2026 \equiv 3^6 = 729 \equiv 4. The number from 0 to 99 that is 1 mod 4 and 4 mod 25 is 29, so 3^2026 ends in 29.

Your turn

What is the remainder when 3^100 is divided by 35?

Solution: Mod 5: 3^4 \equiv 1, so 3^100 \equiv 1. Mod 7: 3^6 \equiv 1 and 100 \equiv 4 \pmod 6, so 3^100 \equiv 3^4 = 81 \equiv 4. The number that is 1 mod 5 and 4 mod 7 is 11.

Practice: master the Chinese Remainder Theorem

Guess first: Practice 1: What is the smallest positive integer that leaves remainders 2, 4 and 6 when divided by 3, 5 and 7?

  • 104
  • 105
  • 209

Each remainder is one less than the divisor, so x \equiv -1 \pmod3, 5, 7, which means x \equiv -1 \pmod105: x = 104.

Your turn

Practice 2: A farmer's eggs leave 1 over when counted in 2s, 3s, 4s, 5s or 6s, and none over in 11s. What is the smallest possible number of eggs?

Solution: The number is 61, 121, 181, …, and 121 = 11 × 11 is the first multiple of 11.

Your turn

Practice 3: Comet A returns every 6 years and was last seen in 2021. Comet B returns every 10 years and was last seen in 2025. In which year will both next appear?

Solution: The year y satisfies y \equiv 5 \pmod 6 and y \equiv 5 \pmod10, so y \equiv 5 \pmod30. The first such year after 2026 is 2045.

Guess first: Practice 4: Which system has NO solution?

  • x ≡ 1 (mod 4) and x ≡ 2 (mod 6)
  • x ≡ 2 (mod 5) and x ≡ 3 (mod 7)
  • x ≡ 0 (mod 6) and x ≡ 3 (mod 9)

\gcd(4, 6) = 2 does not divide 2 - 1: the first congruence makes x odd, the second even. The others work: x = 17 and x = 12.

Your turn

Practice 5: How many integers from 1 to 100 leave remainder 2 when divided by 3 and remainder 3 when divided by 5?

Solution: 8, 23, 38, 53, 68, 83, 98: seven numbers.

Where this shows up in exams: AMC 10 / 12

Remainder puzzles, "smallest number that leaves...", calendars and last-two-digit questions are classic CRT problems on the AMC 10 and AMC 12. Our AMC course has a 50-question CRT test and 10 case studies with worked solutions.

Explore AMC preparation

Try it at home: the mind-reading trick

  1. Ask a friend to think of a number from 0 to 104 and keep it secret.
  2. Ask for the remainders when the number is divided by 3, by 5 and by 7.
  3. Find the number that fits all three remainders using the sieve method.
  4. Announce the secret number. The CRT guarantees there is only one possible answer from 0 to 104.
  5. Swap roles. Can you make the trick work for numbers up to 1000 using 7, 11 and 13?

Quick questions

What is the Chinese Remainder Theorem?

If the moduli m1, ..., mk are pairwise coprime, the system x ≡ a1 (mod m1), ..., x ≡ ak (mod mk) has exactly one solution modulo m1 × m2 × ... × mk.

How do you solve x ≡ 2 (mod 3), x ≡ 3 (mod 5), x ≡ 2 (mod 7)?

x ≡ 2 mod 3 and mod 7 gives x ≡ 2 (mod 21): 2, 23, 44, ... The first that leaves 3 mod 5 is 23, so x ≡ 23 (mod 105).

What if the moduli are not coprime?

The system x ≡ a (mod m), x ≡ b (mod n) has a solution exactly when gcd(m, n) divides a − b, and the solution is then unique modulo lcm(m, n).

Written by the EuclidCurve Smart Team. We are the maths and physics tutors behind EuclidCurve. We teach IB, AMC, ESAT and TMUA students in the UK, USA, UAE, Singapore and Hong Kong, and we write about the maths hiding in everyday life.

Keep exploring

Book a free class · Try today's IMO problem