 One of the most powerful tools in modern number theory is something called the Chinese remainder theorem, and this originates from something known as the Chinese remainder problem. This actually appears in the 3rd century AD, the Chinese mathematician Sun Xi, posed and solved the following problem. So as I have a set of things, if I count them by 3s, 2 remained. If I count them by 5s, 3 remain. If I count them by 7s, 2 remain. And the question is, how many things are there? And because of its origin in an ancient Chinese text, this type of problem has become known as the Chinese remainder problem. And this type of problem actually appears quite often in calendar problems. For example, when is the next time my birthday is going to fall on the Friday of a leap year? Now the solution to the Chinese remainder problem is based on the following key insight. Suppose I have a number, and I have my divisors d1, d2, d3, and so on. And suppose that when I divide n by each of these, I get my remainders r1, r2, r3, and so on, respectively. In other words, when I divide n by d1, I get remainder r1. When I divide n by d2, I get remainder r2, and so on. Now it turns out that if I have n plus the product of all of these divisors, then I'm going to get the same remainders as I had before. So if I take this new number and divide it by d1, I'm going to get the same remainder r1. You should prove this. And so this leads to the following method of solving the Chinese remainder type problems. So for each divisor, what I'm going to do is I'm going to find a product of all the other divisors. I'm going to then take a multiple of this product that meet whatever the requirements are. So this divisor I've isolated, I want to have a certain remainder when I use that. And so I want to find a multiple of this product that has that remainder. And I'm going to do this for each divisor. So I'm going to get a whole bunch of these products, and I'll add these products together. And once I get this number, I might be able to reduce it by subtracting the product of all of the divisors. So let's take a look at Sun G's problem again. So there's three divisors and three remainders. So if the items are counted by threes, then two remained. Well, what that says is that if I take whatever the number is and divide it by three, I get a remainder of two. If counted by fives, three remained. Well, that says that if I divide by five, then my remainder is going to be three. If counted by sevens, two remained. If I divide by seven, then I have two things left over. So we're going to go through each of the divisors. So we'll pick one of the divisors to start with. For example, I'll pick the divisor three. And I want to find the multiple of the other two, five times seven is thirty-five. And I want to find a multiple of thirty-five that solves the requirement of this first divisor, which is if I divide it by three, I'm going to have a remainder of two. And in this case, we're lucky because five times seven is thirty-five does, in fact, have remainder two when divided by three. So we'll write that down. Thirty-five solves the first requirement. Now let's go on to the next divisor, five. And the product of the other two divisors, three times seven is twenty-one. And I want to look for a multiple of twenty-one that solves the second requirement. Again, a multiple of twenty-one that leaves remainder three when divided by five. Well, twenty-one doesn't work. Two times twenty-one is forty-two divided by five doesn't leave remainder three. Three times twenty-one, sixty-three does, in fact, leave remainder three when divided by five. So I'll note that sixty-three solves my second requirement. And let's take a look at that last divisor, seven. And I want to find a multiple of the other two divisors, three and five, fifteen. I want to find a multiple of fifteen that leaves a remainder of two when divided by seven. So again, fifteen doesn't work. Two times fifteen, thirty does work because thirty has remainder two when divided by seven. So thirty is a number that's going to solve our third requirement. One solution we can find by adding all three numbers together, thirty-five plus sixty-three plus thirty, that's one hundred and twenty-eight. But we can also find smaller solutions by subtracting the product of all of the divisors, three, five, and seven. Three times five times seven is one hundred and five. So I can subtract one hundred and five to find a smaller solution. And in fact, the smallest positive solution is going to be one twenty-eight minus one hundred and five is equal to twenty-three. Now, the Chinese version of the Chinese remainder problem involves divisors and remainders, but we can modernize the version of this problem. Remember that n is congruent to r mod d if r is the remainder when n is divided by d. And so that means the Chinese remainder problem is equivalent to solving a system of linear congruences. So this first requirement, when counted by threes, to remain, that's the same as saying when n is divided by three, the remainder is two, n is congruent to two mod three. When counted by fives, three remain. Well, again, that means that when n is divided by five, the remainder is three, n is congruent to three mod five. When counted by sevens, two remains. When n is divided by seven, the remainder is two. And so n is congruent to two mod seven. And I'm looking for a number that solves all three congruences at the same time. And this is the modern statement of the Chinese remainder problem. The actual solution remains unchanged. What we do is we look for multiples of the other divisors, the other moduli that solve the first congruence and we find solutions in this way to all of them, add them, and then subtract the product of all of the divisors, all of the moduli.