 A problem for the mathematical classic of Sonjie in the 3rd century, an unknown number of objects, when counted by 3s, 2 remain, when counted by 5s, 3 remain, and when counted by 7s, 2 remain, how many things? Sonjie's solution, for every unit left when counted by 3s, set 70, for every unit left when counted by 5s, set 21, and for every unit left when counted by 7s, set 15, and since we have 2 left when counted by 3s, we'll set down 270s, since we have 3 left when counted by 5, we'll set down 321s, and since we have 2 left when counted by 7s, we'll set down 15 twice, we'll add, and subtract 210 to obtain 123 the answer. This is the earliest example of what's known as a Chinese remainder problem. So here's a slightly different perspective on the problem. The amounts left when counting by are the remainders when a number is divided. So when we say when counted by 3s, 2 remain, well that's really saying that we have a number with remainder 2 when divided by 3. When counted by 5s, 3 remain, well that's really saying that we have a number with remainder 3 when divided by 5. And finally, when counted by 7s, 2 remain, that's really a number with remainder 2 when divided by 7. So Sun Che found 3 set numbers, 70, 21, add 15, and the thing to notice is that if you add 70 to any number, the remainder when divided by 5 or 7 stays the same, while the remainder when divided by 3 increases by 1. So for example, if we take the number 31, if we divided by 5, 7, or 3, we get remainders of 1, 3, and 1. If we add 70, that makes it 101, dividing by 5 or 7 gives us the same remainder we had, but when we divide by 3, that remainder increases by 1. Similarly, adding 21 doesn't change the remainder when dividing by 3 or 7, but increases the remainder by 1 when dividing by 5, and adding 15 won't change the remainder when dividing by 3 or 5, but increases the remainder by 1 when dividing by 7. And so the important thing here is adding any one of these set numbers changes exactly one of the remainders. And finally, subtracting 210 won't change the remainder when a number is divided by 3, 5, or 7. And so in general, we can solve this problem as follows. Find our set numbers that change exactly one of the remainders. Then find a number that changes none of the remainders. And so the thing to recognize here is that our set numbers are multiples of some of the divisors. So 70 is a multiple of 5 and 7, 21 is a multiple of 3 and 7, and 15 is a multiple of 3 and 5, and this final number 210 is a multiple of 3, 5, and 7. And so all of these numbers are multiples of some or all of the divisors. So let's try this on a simple problem. Let's find the smallest number that leaves a remainder of 3 when divided by 8 and a remainder of 2 when divided by 7. And let's also find those set numbers. So we want to find a multiple of the other divisors. So when I want to leave a remainder of 3 when divided by 8, I want to find a multiple of 7 that leaves 1 when divided by 8. So let's find the remainders when multiples of 7 are divided by 8. And here 49 divided by 8 leaves us remainder 1. And so we can say that for every unit left when counting by 8 set 49. Now the other divisor is going to be 7, so we want to find a multiple of 8 that leaves remainder 1 when divided by 7. Well that's actually pretty easy because 8 itself leaves remainder 1. And so we can say that for every unit left when counting by 7 set 8. And so now for our solution. We have a remainder of 3 when divided by 8. And so for every unit left we're going to set down 49. So we'll set down 3 49s. We have remainder 2 when divided by 7. So for every unit left we'll set down an 8. So we'll set down 2 8s. We'll add them up. And if we add or subtract 7 times 8, 56, we won't change the remainders when dividing by 7 or by 8. And so we can reduce this solution by 56 repeatedly to get smaller solutions and we find our smallest solution will be 51. How about a problem with 3 divisors? So our divisors are 5, 7 and 12. So if I want to change only the remainder when dividing by 5 we want to find the smallest multiple of 7 times 12, 84 that leaves a remainder of 1 when divided by 5. So we'll check our remainders and we find that 3 36 fits this requirement. And so we can say that for every unit left when counting by 5 set 336. Next if I want to change my remainder when dividing by 7 but not by 5 or 12 we want to find the smallest multiple of 5 times 12, 60 that leaves a remainder of 1 when divided by 7. And so we check and we find that 120 works and so for every unit left when counting by 7 set 120. And finally if I want to change the remainder when dividing by 12 but not by 7 or by 5 I want to find the smallest multiple of 5 times 7, 35 that leaves a remainder of 1 when divided by 12. So checking our remainders we find that 385 works and so for every unit left when counting by 12 set 385. And since when counting by 5s 2 remains I'll set down 3 36 twice. When counting by 7s 4 remains so I'll set down 124 times. And when counting by 12s 2 remain so I'll set down 385 twice add them up and get. And we can reduce this by 5 times 7 times 12, 420 to get smaller solutions and so our smallest solution is 242.