Structure preview

The Chinese remainder theorem: from Sunzi to 30 problems

Sunzi’s block method, modern congruences, and 30 interactive challenges involving coins, soldiers, calendars, and trick questions.

Section: Number theory Updated:
Articles /chinese-remainder-theorem-30-problems
The Chinese remainder theorem: from Sunzi to 30 problems

9 min

A merchant groups coins in threes, fives and sevens and obtains a different remainder each time. Can we reconstruct the original total? This is the heart of Chinese remainder problems. The interactive laboratory has thirty progressive challenges, each with a checkable answer, a hint and a solution directly beneath it.

From the Sunzi Suanjing to the number 23

The Sunzi Suanjing, an ancient Chinese mathematical manual, includes a number leaving remainders 2 modulo 3, 3 modulo 5 and 2 modulo 7. Its smallest positive value is 23. The method uses the blocks 70, 21 and 15: the first leaves remainder 1 modulo 3 and is divisible by 5 and 7; the second leaves remainder 1 modulo 5 and is divisible by 3 and 7; the third leaves remainder 1 modulo 7 and is divisible by 3 and 5. Thus 2×70+3×21+2×15=233. Subtracting 105=3×5×7 twice gives 23. This historical account explains why the blocks work.

The modern method: congruences and inverses

We write x≡a (mod n) when division of x by n leaves remainder a. When n₁,n₂,n₃ are pairwise coprime, let N=n₁n₂n₃ and Nᵢ=N/nᵢ. Choose uᵢ so that Nᵢuᵢ≡1 (mod nᵢ). Then x≡a₁N₁u₁+a₂N₂u₂+a₃N₃u₃ (mod N). The historical blocks are an especially simple instance of this construction. For remainders 1,2,3 modulo 3,5,7, the same rule gives 70+42+45=157≡52 (mod 105), so the least positive answer is 52.

Non-coprime moduli: check compatibility first

Not every system has an answer. For x≡a (mod m) and x≡b (mod n), a solution exists exactly when gcd(m,n) divides b−a. If it exists, it is unique modulo lcm(m,n), not necessarily modulo mn. For example, x≡2 (mod 6) and x≡5 (mod 9) are compatible: 5−2=3 is divisible by gcd(6,9)=3, and x≡14 (mod 18). Replacing 5 with 4 makes the difference 2 and the system impossible.

A bound can rule out every answer

The congruence x≡688 (mod 693) has infinitely many integer solutions but no positive one below 500. In a word problem, terms such as “less than” and “between” matter. The laboratory distinguishes an incompatible system from a system whose solutions lie outside the requested interval. For the calendar puzzle, the next occurrences are in 1, 3 and 4 days; saying they “occurred 1, 3 and 4 days ago” would change both the remainders and the answer.

Thirty problems, four levels

The new Chinese remainder puzzles section has beginner, intermediate, advanced and trick questions with no solution under the stated conditions. Each answer is checked against the remainders; the explanation shows successive combinations and the final period. You can try again without opening the solution, and progress stays in your browser. Try the 30 challenges →