Chinese Remainder Theorem
In this article we are going to talk about the Chinese Remainder Theorem. Before I start, I assume the readers have a basic knowledge about Modular arithmetic, because we are going to work in it a lot later.
This is Chinese Remainder Theorem.
Let a1,a2,a3,...,an∈N where they are pairwise relatively prime and let b1,b2,b3,...bn∈Z. Then ∃N∈Z which satisfies the set of simultaneous congruences N≡bi(modai) where i=1,2,3,...,n
In fact, this theorem has been existed and implemented in the early days. Let's try two famous examples and you are going to try another one. Credits to Cut The Knot.
Example 1. (Sun Tsu Suan-Ching, 4th Century AD)
There exists a number which is unknown. If divided by 3, it gives remainder of 2; by 5, the remainder is 3; by 7, the remainder is 2. Find the number. (Find the least, because there are lots of number that satisfy this condition)
Solution 1. We start by writing three congruence relations. We have
xxx≡2(mod3)≡3(mod5)≡2(mod7)
Now, set x=3x1+2 (why?) such that x1 is integer and substitute it into the second congruence relation. We have
3x1+2⟹3x1≡3(mod5)≡1(mod5)
Here comes the tricky part.
Now, let's try add one 5 to the RHS. We have
3x1⟹x1≡6(mod5)≡2(mod5)
Cheers! Now set x1=5x2+2 and substitute it back to the first equation to get
3x1+2=3(5x2+2)+2=15x2+8(@)
So we can see that 8 is the first number to satisfy the first two congruence relations. But we are not done yet, we need to substitute (@) into the third congruence relation. So, using the steps above, we get
15x2+8≡2(mod7)⟹15x2≡−6(mod7)
Now, instead of adding 5 on the RHS, we add 7 (why?). We have
15x2≡−6(mod7)⟹15x2≡1(mod7)
Uh oh, it seems like adding 7 is not enough...So, we will have to keep adding 7 so that it perfectly divides 15. We then have
x2≡1(mod7)⟹x2=7x3+1
Last step! Substitute back x2=7x3+6 into (@), we get 15x2+8=15(7x3+1)+8=105x3+23 and we are done! The least number that satisfies the condition is 23.
Example 2. (A Chinese Idiom Story? Han Xin has 1500 soldiers and about 400 to 500 of them had died. If the soldiers were to stand 3 in a row, we left 2 soldiers, if 5 in a row, we left 4 soldiers, and if 7 in a row, we left 6 soldiers. How many soldiers are there?
Solution 2. Same as example 1, start with 3 congruence relations,
xxx≡2(mod3)≡4(mod5)≡6(mod7)
Now, set x=3x1+2 and substitute the second congruence. We have
3x1+2⟹3x1≡4(mod5)≡2(mod5)
Remember that you can't divide by 3 on both sides for now, we are going to add some more 5's on RHS until 3∣2+5k. So, we have
3x1≡12(mod5)⟹x1≡4(mod5)⟹x1=5x2+4
and, for x, it now becomes x=3x1+2=3(5x2+4)+2=15x2+14. Now substitute this to the last congruence and using the steps above, we get x2≡6(mod7)⟹x2=7x3+6 (the steps here are left as an exercise to the reader).
For the penultimate step, substitute 7x3+6 into 15x2+14 to get 105x3+104.
Since the number of soldiers died is around 400 to 500, we can say that the number of soldiers left is
1000<105x3+104<1100
⟹8158<x3<93517
Therefore, substituting x3=9 we get the number of soldiers left is 1049.
Last problem! This time, you are going to do it.
(Brahma-Sphuta-Siddhanta) Add old woman goes to the market and a horse steps on her basket and crushes the eggs. The rider offers to pay for the damages and asks her how many eggs she had bought. She does not remember the exact number, but when she had taken them out 2 at a time, there was one egg left. The same happened when she picked them out 3, 4, 5, 6 at a time, but when she took them 7 at a time, they came out even. What is the smallest number of eggs she could have had?
Happy solving and that's it for this post.