 Let's take a deeper look at the Chinese remainder problem algorithm. And here I'll introduce an important warning. The danger of using an algorithm that you didn't create is a lot like using a power tool. Power tools are great ways of getting things done, but if you're not careful, you can do some real damage or cause some serious injuries to yourself. And with power tools, you should always read the owner's manual. And in the case of mathematical algorithms, this means that you need to understand why the algorithm works and why it won't work. So let's take a look at a problem. We want to find a number that leaves remainder 1 when divided by 3, remainder 4 when divided by 5, and remainder 5 when divided by 6. Well, again, the Chinese remainder problem is equivalent to solving a system of simultaneous congruences, remainder 1 when divided by 3. So I'm looking for a number that's congruent to 1 mod 3, remainder 4 when divided by 5. I'm looking for a number that's congruent to 4 mod 5, and remainder 5 when divided by 6. I'm looking for a number that's congruent to 5 mod 6. So our first step in applying the algorithm is to find a multiple of mod 5 mod 6 5 times 6, a multiple of 30, that leaves remainder 1 when divided by 3. So I'll check it out, 30, congruent to 0 mod 3, nope, 60, congruent to 0 mod 3, nope, 90, congruent to 0 mod 3, nope. And I could continue, but it's worth keeping in mind a very useful rule of life, once is an accident, twice is coincidence, but 3 times suggests that there's actually something going on here. And so let's analyze our failure. So the problem is that when we found these multiples of 5 times 6, this number was always divisible by 3, so we could never get a remainder of 1 when divided by 3. And well, why did this happen? Well, we might note that a multiple of 5 times 6, since 6 is 2 times 3, this is also a multiple of 3, and so this will always leave a remainder of 0 when divided by 3. And what this suggests is that if two divisors are not relatively prime, we might not actually be able to solve the Chinese remainder problem because those divisors will get, in some sense, tangled up. And well, if the divisors aren't relatively prime, we should see if we can solve the problem by modifying our approach in some fashion. So here the apparent problem is the divisor is 6, and we need a number that has a remainder of 5 when divided by 6. Well, let's see what we can do about that. Suppose I have a number n that has a remainder of 5 when divided by 6. Well, I know that n is 6k plus 5, it's 5 more than a multiple of 6. But what I might ask is, what's the remainder when the number is divided by 3? Well, we'll apply a standard strategy in mathematical research, we'll write down where we want to end up, n divided by 3 is something with some remainder, and I'll work a couple steps back. This says that n is 3 times something plus something. Next, we'll include what we actually know at the start. We know that n is a 6k plus 5 number, and we'll use a little bit of algebra to see if we can connect, start, to finish. So let's see, I want n to be 3 times something plus something. So let's split off our 6k plus 5 into a portion that I can write as 3 times something. I'll do a little bit of algebra, and I have n is 3 times quantity 2k plus 1 plus 2, and that says n divided by 3 is 2k plus 1, and we'll be guaranteed to have remainder 2. And what this means is that if I have a number that has remainder 5 when divided by 6, that number must have remainder 2 when divided by 3. And this tells us two things. One is that our original problem is unsolvable. We cannot have a number with remainder 1 when divided by 3, as well as having remainder 5 when divided by 6. At the same time, this also says that if I had remainder 2 when divided by 3, then that problem would be solvable. So we'll change our problem so we have remainder 2 when divided by 3. And again, we determine that if we meet this third requirement, remainder 5 when divided by 6, we automatically satisfy the first requirement. We automatically have remainder 2 when divided by 3. And what this really means is we don't actually need that first requirement. We'll ignore it because it doesn't make a difference. And so now I have a Chinese remainder problem, and this time I only have two divisors, 5 and 6. So I want to find a multiple of the product of the other divisors. Well, there's only one 6. I want to find a multiple of 6 that leaves remainder 4 when divided by 5, and 24 works. And I want to find a multiple of 5 that leaves remainder 5 when divided by 6. And, well, 5 works. 5 is a multiple of 5, and it does leave remainder 5 when divided by 6. And again, importantly, this satisfies that first requirement that we ignored. So we have something that actually satisfies all three requirements. And now I have my solutions, 24 and 5. I'll add them together to get one solution, 29. And the product of the two divisors, 5 and 6, 30. Well, I can't subtract 30 from 29, so this is actually the smallest solution. Now, the proceedings suggest the following way of extending the Chinese remainder problem algorithm. So if I have a number with some remainder when divided by p times q, where p and q are relatively prime, then I have a number that has the remainder r1 when divided by p, and remainder same r1 when divided by q. Now, remainder here should be taken with a little bit of a grain of salt because we may have to do something to modify those remainders. We'll see how that works. But that does suggest a way of extending our Chinese remainder problem algorithm. So what we'll do is we'll rewrite all of the remainder statements by factoring the divisors into relatively prime factors. We may be able to reduce some of these, and importantly, we'll be able to eliminate any sort of requirements that are repeated. At the same time, if any of our requirements are contradictory, a number having different remainders when divided by the same thing, then we're going to be able to identify the problem as unsolvable. If not, well, then we'll have a system of linear congruences that we'll be able to solve in the same way that we did before. And let's take a different problem. I want to find a number that leaves remainder, or how about 3 when divided by 15, and remainder 8 when divided by 20. And so again, I'll rewrite those congruences as the moduli are relatively prime. x is congruent to 3 mod, well, 15 is 3 times 5. So x congruent to 3 mod 3 is the same as x congruent to 0 mod 3. x congruent to 3 mod 5 is, I can't reduce this, x congruent to 8, well, I'm going to split 20 as 4 times 5. So x congruent to 8 mod 4, that's the same as 0 mod 4, and x congruent to 8 mod 5, that's the same as 3 mod 5. And my congruences mod 5 are the same x congruent to 3, x congruent to 3. So this problem is solvable, and I don't actually need this repeated congruence. So I have 3 divisors, 3, 4, and 5. So I'll start out by finding a multiple of 4 times 5, so a multiple of 20, that's congruent to 0 mod 3. And 60 seems to work out for that. Next, I'll want to find a multiple of 3 times 5, that's congruent to 0 mod 4. And so 3 times 5 is 15, I want to find a multiple of 15 that leaves the remainder 0 when divided by 4. And 60 also works for that. And then finally, I want to find a multiple of 3 times 4, a multiple of 12, that leaves remainder 3 when divided by 5. And so going through our multiples of 12, we find that 48 works. And so adding 60, 60, and 48 together, 168, is one solution to our problem. And I can repeatedly subtract a product of our divisors, 3, 4, and 5. 3 times 4 times 5 is 60. I can repeatedly subtract 60 until I get a smallest possible solution. So 48 is going to be the smallest positive solution to this problem.