Chinese Remainder Puzzles
A puzzle gives you a number's remainder against several small divisors and asks you to find it, or to prove it's unique. The Chinese Remainder Theorem is the reusable machinery for turning a stack of remainder clues into one answer.
Prerequisites: GCD and LCM Puzzles
A basket of eggs, counted in groups, always has some left over. Counted by twos, one is left. By threes, two are left. By fives, four are left. What's the smallest number of eggs in the basket?
Try it before reading on — you can brute-force small cases in your head, but the puzzle is really asking for a method, since interviewers love to follow up with bigger, uglier divisors where guessing stops working.
The clues, translated
Each clue is a remainder statement. "Left one over when counted by twos" means the count satisfies — in words, dividing by 2 leaves remainder 1. Our basket gives three such clues:
Each one alone allows infinitely many values of : 1, 3, 5, 7, 9, ... satisfy the first; 2, 5, 8, 11, ... satisfy the second. The question is what happens when all three must hold at once.
Why a unique answer exists at all
Here's the fact that makes this whole puzzle type work, known as the Chinese Remainder Theorem. If the divisors — here 2, 3, 5 — share no common factors with each other (they're pairwise coprime), then a system of remainder clues against them has exactly one solution modulo the product of the divisors. The product here is , so there is exactly one answer between 0 and 29, and every valid basket size is that answer plus a multiple of 30.
The intuition: think of three clock faces with 2, 3, and 5 hours on them respectively, all ticking together as counts up 0, 1, 2, 3, .... The three hands return to their starting positions simultaneously only once every steps, because 2, 3, and 5 share no common factor. Until then, every combination of hand positions is visited exactly once — so the combination "1 on the first clock, 2 on the second, 4 on the third" pins down uniquely within that 30-step cycle.
Solving the egg basket
The fastest hand method is successive substitution: solve two clues at a time, fold the result into a single new clue, then bring in the next divisor.
Step 1 — combine the mod-2 and mod-3 clues. Numbers that are : 1, 3, 5, 7, 9, 11, .... Which of these are also ? Check them in order: (no), (no), (yes). So — the combined clue, since .
Step 2 — fold in the mod-5 clue. Numbers that are : 5, 11, 17, 23, 29, .... Which are also ? Check: (no), (no), (no), (no), (yes). So .
Answer: the smallest basket has 29 eggs. Quick sanity check: (one left over by twos, correct), (two left over by threes, correct), (four left over by fives, correct). All three clues hold, and 29 is the smallest such number below the cycle length of 30.
Combine clues two at a time: list the numbers satisfying the first, walk them in order, and stop at the first one that also satisfies the second. That gives one new clue modulo the product of the two divisors. Repeat with the next divisor.
A second example: shifting the pattern
A number leaves remainder 3 when divided by 4, and remainder 5 when divided by 7. What is it, mod 28?
List numbers that are : 3, 7, 11, 15, 19, 23, .... Check each against "remainder 5 mod 7": (no), (no), (no), (no), (yes). So , since . Notice the trick generalizes instantly — you never needed algebra, just an ordered walk down one list checking against the other condition.
If the divisors are not coprime — say 4 and 6 — check the clues are consistent on their shared factor (here, both must agree mod 2) before combining; otherwise no solution exists at all.
Where this shows up beyond eggs
The reusable move is: a system of "leftover" constraints against coprime divisors collapses to one clue modulo their product. This is the same machinery behind why calendar-cycle puzzles ("this day of the week and this day of the month coincide every how-many years?") and hashing schemes that combine multiple small moduli for a larger effective range both have clean, unique-cycle answers. In quant interviews it resurfaces disguised as scheduling puzzles, cyclic-index problems, and any "when do these two periodic things line up again" question — recognize the shape and skip straight to combining remainders pairwise.
Related concepts
Practice in interviews
Further reading
- Engel, Problem-Solving Strategies (ch. 4, Congruences)
- Andreescu & Andrica, Number Theory: Structures, Examples, and Problems