Sometime between the 3rd and 5th centuries, a Chinese author wrote down a riddle about counting objects and leftovers. It looks like a party trick, yet it grew into a theorem that now sits inside the security of your browser.
The riddle that started it
The riddle appears in the Sunzi Suanjing, a Chinese manuscript from the 3rd to 5th century. It asks: “There are certain things whose number is unknown. If we count them by threes, we have two left over; by fives, we have three left over; and by sevens, two are left over. How many things are there?”
The smallest answer is 23. Count 23 things by threes and two are left over, by fives and three are left over, by sevens and two are left over.
Here is the catch. By modern standards, Sunzi’s work would not count as a theorem. It gives one particular problem, without showing how to solve it, and certainly without any proof of the general case.
What the theorem actually says
In plain words: if you know the leftovers after dividing a number by several divisors, and no two divisors share a common factor other than 1, then you can pin down the number’s leftover when divided by their product. There is exactly one answer in that range.
In the riddle, 3, 5 and 7 multiply to 105. So the three leftovers fix a single number between 0 and 104.
Why only one? Two different numbers with the same leftovers would differ by a multiple of 3, of 5 and of 7. Since those divisors share no common factor, the difference must be a multiple of 105 as well.
A relay that crossed continents
An algorithm for the problem was described by Aryabhata in the 6th century. Special cases were also known to Brahmagupta in the 7th century, and they appear in Fibonacci’s Liber Abaci in 1202.
The complete solution came in 1247, in Qin Jiushao’s Mathematical Treatise in Nine Sections. He called it Da-yan-shu (大衍術). The book was translated into English only in the early 19th century, by the British missionary Alexander Wylie.
Gauss and the calendar
The modern language of congruences was introduced by Carl Friedrich Gauss in his Disquisitiones Arithmeticae of 1801. To show the theorem at work, Gauss picked a calendar problem: “to find the years that have a certain period number with respect to the solar and lunar cycle and the Roman indiction.”
His procedure had already been used by Euler. It was, in the words of the sources, an ancient method that had appeared several times, rediscovered again and again.
Where it hides today
The theorem’s real power is a shortcut. It lets you replace one huge computation with several small ones on small numbers, then stitch the answers back together.
That trick is everywhere. Most implementations of RSA use it when signing HTTPS certificates and when decrypting. It is also used in secret sharing, where each person holds one congruence and only the whole group can recover the secret. Medium pulse repetition frequency radar relies on a special case of it to resolve range ambiguity. It even helped build the numbering of sequences used in the proof of Gödel’s incompleteness theorems, and it powers a fast Fourier transform algorithm.
Leftovers worth keeping
A riddle about what remains after counting was once a curiosity in a manuscript. Passed from China to India to Italy and back into Gauss’s hands, it became a tool that quietly shrinks the cost of the math behind every secure page you open. The leftovers turned out to be the most valuable part.

