 Welcome back, we are looking at solutions of linear congruence equations, modulo sum natural number n. We saw that if you take this linear congruence which is say A x congruent to B mod n, then the solution exists exactly when you have that this GCD of A and n divides B. So, this holds that the condition really is on A and n. The condition on B is a very mild condition that you should have that this GCD D divides B that is a very mild condition which is there on B. So, for instance if D is 1 or equivalently A and A is co-prime to n then the above congruence solutions for B. So, the only important thing here is to note that A is the only important thing. You should look at the GCD of A and n and the mild condition on B is that D should divide B. So, I told you in the last lecture that when you are looking at solutions to linear congruences then there are two problems which is that there may not be a solution, but now we have gone modulo this problem so to say by putting a condition on the GCD of A and n. So, now we know when there may when exactly when there can be solution, but sometimes there are not unique solutions as we have seen in the clock arithmetic already. So, when there are not unique solutions can we get the exact number of all solutions that is the question. If there are no unique solutions how many different solutions can there be? That is the question that we want to answer and this question is related very nicely with the quotient of n and D. So, this is what we have in the next slide. If you have a solution x naught to the above linear congruence. So, remember the above linear congruence was our x congruent to be modulo n. If you have a solution then all solutions are of the form x naught which is one solution that you had plus n upon D into t where t varies over all integers. So, the statement is quite simple if you have one solution all other solutions are obtained by adding multiples of n by D to that solution and you get all other solutions. So, to show to prove this lemma what we will have to do is to show that whenever you have x naught to be a solution then x naught plus n by D into t is also a solution for every t. This would be one statement one direction of proving this lemma. Second direction would be to show that any other solution is also of this form. These are the two directions that we will have to prove. So, this is a very important corollary that whenever you are looking at it modulo n then you will have exactly D solutions modulo n. So, these will be given by x naught plus n by D and before that you will have x naught x naught plus 2 n by D. So, on all the way up to x naught plus n minus 1 into n by D these are n different solutions. These are all different first of all note that this n by D is a natural number because you have D to be the GCD of a and n. So, in particular D should divide n therefore, n by D is a natural number and so, but it is a smaller number than n and when you add that number to x naught you do not get same elements modulo n. In fact, you do not get the same elements modulo n until you add n times this number. So, these are precisely the D solutions I should have said instead of D minus 1 I should put instead of n minus 1 I should put D minus 1 because when you take the next one it would be x naught plus D n by D which would be x naught plus n and then you would get the same number. So, let us go about proving this. So, first of all we assume that the x naught is a solution x naught is congruent to b mod n. So, x naught is assumed to be a solution to this linear congruence and take x 1 to be x naught plus n by D into t for some t in integers you can take it to be any t. Now it is very simple what we just want to prove is that a x 1 is congruent to b mod n this is the only thing to prove. So, we need to prove that a x 1 is congruent to b mod n this is all. So, let us go about proving it. So, a x 1 is a x naught plus n by D into t which gives you a x naught plus a n by D into t, but note that D being the GCD of a and n D divides a as well and therefore this is congruent to a x naught mod n because now we have that all these elements are integers. So, we have written a x 1 to be equal to a x naught plus n times an integer and therefore we get that a x naught is congruent to a x 1 mod n and thus we get it to be congruent to b mod n. So, one side was quite easy we assumed that x naught is a solution and then we proved that any x 1 which is given by x naught plus n by D t is also a solution. Now we have to prove the other direction which is that we will start by assuming that there are two solutions and we will prove that the other solution is equal to the first solution plus an integer multiple of n by D this is what we need to prove. Two solutions x naught x 1 to a x congruent to b mod n are related by x 1 equal to x naught plus n by D t for some integer t this is what we want to prove. So, let us begin. So, we have that a x naught is congruent to a x 1 modulo n because both are congruent to b mod n. So, we get that a x naught is congruent to a x 1 mod n and which further implies that n divides a x naught minus a x 1 which we can write as a into x naught minus x 1. Now, we have that D the GCD divides both n and a. So, we can cancel out GCD from this equation or alternately we have that a into x naught minus x 1 is say n into t because n divides this difference a into x naught minus x 1 we have that a x naught minus x 1 is n into t which further gives us. So, we have that a x naught minus x 1 is n into t and this gives us that D into a by D x naught minus x 1 is D into n by D t. So, these D's can be cancelled to get that n by D divides a by D into x naught minus x 1. So, here we have two integers one is this a by D and the other is n by D and we have that n by D divides a by D into x naught minus x 1. The GCD that was there for both a and n has now been cancelled on both sides. Therefore, the GCD of a by D and n by D is equal to 1. There is no common prime factor between n by D and a by D. So, all the prime factors of n by D would go and divide the difference x naught minus x 1 with all the powers that it would divide n by D it would divide the difference x naught minus x 1. So, what we therefore get is so since this GCD is 1 we get n by D divides x naught minus x 1 or x 1 is x naught plus n by D into some s. So, what we have proved here is that any two solutions to the congruence A x congruent to B mod n differ by a multiple of n by D. And therefore, when we saw the example in earlier about clock arithmetic where we had 2 x congruent to 8 modulo 12 the GCD of 2 and 12 was 2 and so we got exactly 2 solutions there 4 into 2 is 8 similarly 10 into 2 is also 8 and n by D remember n is 12 D is 2. So, n by D is 6 and indeed 4 and 10 differ by 6 that was the only difference between 4 and 10. So, any two solutions differ by a multiple of n by D and if you have got one solution any other solution is obtained by adding a multiple of n by D. So, this way we get a complete description to the solutions to the linear congruence A x congruent to B mod n with this let us go and do some simple examples to get hang of this correctly. So, suppose we are asked to solve the linear congruence 7 x congruent to 3 modulo 12. So, first of all what we do is to find the GCD in this case this GCD is 1. So, we always have solutions. So, there are solutions congruence it is unique modulo 12. So, to find the solution we invert 7 it is like 7 x is 3 in some space of numbers and to compute x we need to multiply by the inverse of 7 this is what we want to do. So, what is the inverse of 7 modulo 12. So, we go about multiplying by all numbers modulo 12 to 7 and see when we get 1. So, 7 into 1 is 7 7 into 2 is 14 that gives us 2 modulo 12 7 into 3 is 21 7 into 4 is 28 7 into 5 is 35 35 is minus 1 modulo 12 and therefore, so we have 7 into 5 equal to minus 1 modulo 12. So, if I multiply both sides by minus 1 I will get 7 into minus 5 equal to 1 modulo 12. So, minus 5 is the multiplicative inverse of 7 modulo 12 what is minus 5 in 12 minus 5 is same as 12 minus 5 which is again 7. So, 7 chi inverse is 7 therefore, to find the solution for 7 x congruent to 3 we simply multiply both sides by 7 7 x congruent to 3 mod 12 7 into 7 x is congruent to 7 into 3 this side is 21 or 9 modulo 12 and this side we simply get 49 which is simply x. So, thus x congruent to 9 mod 12 is the unique solution the above congruence. You can simply check this by putting the value x equal to 9 in the equation. So, you have 9 into 7 which gives you 63 and 63 is indeed 63 plus 3 60 0 modulo 12. So, you get 3 modulo 12. So, this is how one would solve linear congruences. Let us also see one more problem where we have multiple solutions when we do not have a unique solution. So, the question now is to find all solutions to 10 x congruent to 6 modulo 14. We are doing some other number than the 12 which has been our favorite number so far. So, first of all we check whether there is a solution at all. We first check there is a solution and we know how to do this D which is the GCD of 10 and 14. Now, it should be a simple matter to compute GCDs. This GCD is 2 and 2 divides 6. So, we do have a solution at least one solution. So, since D is not 1 we do not have a unique solution but D is 2. So, we are going to get 2 distinct solutions. So, we are going to get 2 solutions modulo 14. Now, there should be a nice algorithm to solve such equations such congruence relations. We will see whether there is such an algorithm but let us just try our hand and solve this problem. So, what we want to do first of all is to solve for 10 x congruent to 6 modulo 14 and we observe it is enough to solve 5 x congruent to 3 mod 7. Why is this enough to solve? This is because if you had an x naught such that so if 7 divided 5 x naught minus 3 then 14 we divide 10 x naught minus 6. We are just multiplying by 2 to both the sides. So, that would tell us that whenever you have the GCD you can simply cancel out by the GCD throughout the equation including the natural number by which you are going modulo including the n such that you are working in Zn you can cancel D throughout the linear congruence. So, we want to now solve this here the GCD of 5 and 7 is 1. So, indeed we should have a solution that was no surprise because we already know that there is a solution but what we do is so we need to find a number alpha in Z7 such that 5 into alpha is 1. This is what we need to do we need to be able to invert 5 and this is possible because we have that the GCD is 1. So, 5 into 1 is 5, 5 into 2 is 10 which is not 1 modulo 7, 5 into 3 is 15 which is 1 mod 7. So, alpha is 3. So, we need to multiply by 3 to both the sides. So, we are solving 5x congruent to 3 mod 7 and 5x into 3 is congruent to 3 into 3 mod 7, 3 into 3 is 9 which is 2 modulo 7, 5 into 3 is 15, 15x is x modulo 7. So, we get that x is 2 mod 7. So, x not equal to 2 is indeed a solution the congruence given in the question because if you put 2 in 10x you get 10 into 2 which is 20 and 20 is indeed congruent to 6 modulo 14. So, 2 is a solution what can be the other solution. So, remember n is 14, d is 2. So, n by d is 7 and therefore 2 plus 7 which is 9 that is one more solution because 10 into 9 is 90 and 90 is 84 plus 6, 84 is a multiple of 14 and therefore 90 is also 6 modulo 14. So, thus 2 plus 7 which is 9 are all these solutions were congruence. So, we have solved the problem we found all possible solutions there are only 2 because the GCD is equal to 2 and whenever the GCD is 1 we convert from the GCD 2 case to the GCD 1 case and then we try to invert the coefficient of x this is what we do and I told you that it would be nice to have an algorithm to solve these linear congruences. So, indeed there is an algorithm which we have been following up to now the algorithm is as follows what we do first of all is to check whether the GCD d of a and n divides b this is the most important case. So, if this does not happen if the GCD does not divide b there are no solutions and then we are done we will just say that there is no solution. However, if the GCD does divide n then what we do as we have done in the previous case we solve for this a by d x congruent to b by d modulo n by d and so we need to prove a small lemma that whenever there is a solution for this there is a solution for the a x congruent to b and whenever there is a solution for that we get a solution for this we will need to prove equivalence of existence of solutions for these both congruences and the final thing which we wanted to do was to try and invert the coefficient of x which is a by d. Now what happens is that a by d is co-prime to n by d and therefore we know that a by d into x congruent to 1 modulo n by d should have a solution because the GCD is 1 which divides 1 which means that we should be able to invert a by d but to invert a by d is in some sense equivalent to getting solutions indeed inverse of a by d modulo n by d is nothing but the solution to a by d into x congruent to 1 mod n by d. So, there should be a better way to do it and what we then want to do is to reduce the magnitude of this a by d we will try to make it smaller and smaller by using some other tricks and then ultimately we will solve the congruence relation. So, we will see some more of these methods in the next lecture and then we will go to what is called the simultaneous congruence which is about the Chinese remainder theorem. See you until then. Thank you.