Chapter 3: Theory of Modular Arithmetic 25 SECTION C Solving Linear Congruences By the end of this section you will be able to solve congruence equations determine the number of solutions find the multiplicative inverse C Solving Linear Congruences In algebra we have linear equations in one unknown x given by Solving this equation gives x 3. 2x 7 A linear congruence in modular arithmetic is an equation of the form ax b mod n The solution to this linear congruence is the set of integers x which satisfy this: ax b mod n Why is the solution a set of integers rather than a unique integer? Recall ax b mod n integer k. means that ax b is a multiple of n or ax b kn for some As we have often stated, in mathematics we are interested in a unique solution if possible. How can we find a unique solution to the linear congruence? If two solutions x x and x x satisfy the linear congruence 0 ax b mod n and they are congruent modulo n, that is x x 0 mod n same solution and count them as one solution. For example let us consider the linear congruence We can trial a table of integers for x: 2 x mod 5 (*), then we say these are the x 0 2 3 4 5 6 7 8 9 2 x mod 5 0 2 4 3 0 2 4 3 Therefore x 3 and x 8 Table Shows the junctions of 2x mod 5 satisfy
Chapter 3: Theory of Modular Arithmetic 26 2 x mod 5 because 23 6 mod 5 and 2 8 6 mod 5. Hence integers 3 and 8 satisfy the linear congruence (*). They are the same solution. Why? Because 8 3 mod 5. We count this as one solution not two. [It is the same station in modulo 5 clock.] Since we are interested in solutions modulo 5 we only need to consider integers amongst the list; x 0,, 2, 3 and 4 [least non-negative residues modulo 5] Because all the other solutions will be one of these in modulo 5 which is illustrated below: x 0,, 2, 3, 4 mod 5 these junctions. Figure 7 Modulo 5 clock covers all the stops. Any other integer will stop at one of A more systematic way of solving the above linear congruence is given next. Example 0 Determine the integers x of the following linear congruence: 2 x mod 5 By definition of congruence 2x mod 5 implies that 2x is a multiple of 5: 2x 5y where y is an integer Rearranging this we have 2x 5y which is a Diophantine equation and we solved these type of equations in chapter. Making x the subject of 2x 5y gives 5y x 2 Remember x must be an integer. So what values of y can we use?
Chapter 3: Theory of Modular Arithmetic 27 Only the odd integers because if we choose even then we get even plus which does not give a whole number after dividing by 2. Substituting y, 3, 5,,, 3, 5, gives y 5 3 3 5 5y x 25 2 5 7 5 2 5 5 25 3 8 3 2 2 2 2 2 2 2 Table 2 x values for particular y values Therefore x, 2, 7, 2, 3, 8, 3, Clearly there are an infinite number of integers which satisfy the given congruence 2 x mod 5 We count all these solutions as one or the same solution because they are all congruent to each other modulo 5: 3 8 3 2 7 mod 5 See the above Fig. 7 and you will notice that all these numbers 3, 8, 3,, 2, 7 stop at the same junction, 3 mod 5. We normally write this as just one solution which is the least non-negative residue modulo 5: x 3 mod 5 We say the solution of 2x mod 5 is 3 mod 5 x. Example Solve the linear congruence: 2 x mod 6 The solution (if it exists) of this linear congruence 2x mod 6 x 0,, 2, 3, 4 and 5 must be in the list: Because we are working with modulo 6 in this case. Evaluating these we have x 0 2 3 4 5 2 x mod 6 0 2 4 0 2 4 Table 3 Junctions of 2x mod 6. [Note that the numbers 0, 2 and 4 are repeated]. By examining this table we find that there are no x values which satisfy
Chapter 3: Theory of Modular Arithmetic 28 2 x mod 6. The set of integers 2x will not stop at junction modulo 6. This means that there is no solution to the given linear congruence 2x mod 6. (Try doing this by solving the Diophantine equation 2x 6y.) If we have x b mod n In solving 2x mod 5 then we only have to consider values of x 0,, 2, 3,, n. we tried values of x up to 9 (see Table at the beginning of this section), but we only need to try x 0,, 2, 3, 4. C2 Number of solutions of a Linear Congruence The above Example demonstrates that there are some linear congruences which have no solution. How do we know which congruences have a solution? The next proposition gives the criteria for a solution. Proposition (3.5). The linear congruence ax b mod n has a solution g b where g gcd a, n. Note that in Example 0 we had 2x mod 5. The the linear congruence 2x mod 5 has a solution. g gcd 2, 5 and so On the other hand in Example we had 2x mod 6 the g gcd 2, 6 2 and 2 does not divide so there are no solutions to this linear congruence. (For this example you would have noticed from the previous table that 2x mod 6 only stops at 0, 2 and 4 modulo 6 because these numbers are multiples of g gcd2, 6 2.) How do we prove this proposition (3.5)? By Proposition (.6) of chapter : Proof. ax by c has integer solutions g c We have ax b mod n where gcd, a b g which means that there is an integer k such that ax b kn ax kn ax k n b implies
Chapter 3: Theory of Modular Arithmetic 29 Let g gcd a, n. Then by Proposition (.6) we conclude that the Diophantine equation ax k n b has a solution g b which is our required result. Example 2 Which of the following linear congruences have solutions? (a) 7x 8 mod 4 (b) 2x 8 mod 6 (c) 5x 2 mod 9 (d) 36x 54 mod 90 (a) We are given 7x 8 mod 4. The greatest common divisor of 7 and 4, that is gcd 7, congruence 4, is 7 but 7 does not divide 8 so by the above Proposition (3.5) the linear 7 x 8 mod 4 (b) For 2x 8 mod 6 the congruence 2 x 8 mod 6 (c) For 5x 2 mod 9 we have linear congruence has no solution gcd 2, 6 6 but 6 8 so the given linear has no solution 5 x 2 (d) We are given 36x 54 mod 90. The the given linear congruence 36x 54 mod 90 gcd 5, 9 3 and 3 divides 2 so the given has solutions (we are not asked to find them) gcd 36, 90 8 and 8 divides 54 so has solutions. Next we show that the linear congruence ax b mod n has exactly g gcd a, n incongruent solutions. What does incongruent mean? Not congruent. For example 6 x 2 mod 4 has solutions x mod 4 and x 3 mod 4 but
Chapter 3: Theory of Modular Arithmetic 30 3 mod 4 [ 3 mod 4 is not congruent to We say x mod 4 and x 3 mod 4 linear congruence 6x 2 mod 4. These congruences x mod 4 and x 3 mod 4 Example 3 are two different stops on the modulo 4 clock. Solve the linear congruence 6x 3 mod 9. mod 4 ] are two incongruent solutions of the given We use the above Proposition (3.5) to test whether the given congruence has a solution: mod has a solution g b where g gcd a, n ax b n We first find the greatest common divisor of 6 and 9: g gcd 6, 9 3 Since 3 3 the given linear congruence 6x 3 mod 9. has solutions. In this case we are working with modulo 9 so we only need to consider x 0,, 2, 3, 4, 5, 6, 7 and 8 Evaluating these gives x 0 2 3 4 5 6 7 8 6 x mod 9 0 6 3 0 6 3 0 6 3 By using this table we see our solutions are Table 4 Shows junctions of 6x mod 9 x 2, 5, 8 mod 9 The linear congruence 6x 3 mod 9 has three solutions 2, 5, 8 mod 9 By observing Table 4 in Example 3 we have that the congruences 6 x 0, 3, 6 mod 9 x. have solutions because all these numbers 0, 3, 6 are multiples of 3 which is the gcd of 6 and 9. The set of integers represented by 6x mod 9 0, 3, 6 on the modulo 9 clock. only stops at junctions However the following congruence equations 6x, 2, 4 and 5 mod 9 will have no solutions because g 3 does not divide into any of these numbers, 2, 4 and 5.
Chapter 3: Theory of Modular Arithmetic 3 Proposition (3.6). The linear congruence ax b mod n Has exactly g incongruent solutions modulo n provided g b where g gcd a, n How do we prove this result?. We use Proposition (.7) of chapter which gives the solutions of the Diophantine equation: If x 0, y 0 are particular solutions of the Diophantine equation and g c where gcd a, b g by Proof. ax by c then all the other solutions of this equation are given b x x t 0 g a and y y t 0 g We do the proof in two parts. First we list the solutions and then we show there are exactly g incongruent solutions. The given congruence ax b mod n ax b kn implies that there is an integer k such that ax kn ax n k b which implies Let x 0 be a particular solution to this equation then by applying the above Proposition (.7) to ax n k b gives the other solutions as n x x t 0 g where t is an arbitrary integer and g gcd a, n Substituting t 0, t, t 2, and t g we have n n n n x x, x, x 2, x 3,, x 0 0 0 0 0 g g g g g (*) Need to show that each of these are not congruent modulo n. How? Use proof by contradiction. Suppose any two numbers in the list (*) are congruent modulo n: n n x t x t 0 2 0 mod n g g Where 0 t t g. By using Definition (3.): 2 a b mod n a b kn
Chapter 3: Theory of Modular Arithmetic 32 g g On n n x t 0 2 x t 0 mod n implies there is an integer k such that n n x t 0 2 x t k n 0 g g n t t 2 k n Simplifying and factorizing g t t k g implies t t k g 2 2 Cancelling n's We have t 2 t k g t g g (because k ) and earlier we had t 2 g. This is a contradiction because we have t 2 g and t 2 g. Hence none of the congruences in the above list (*) are congruent to each other modulo n. This means that the list of numbers: are incongruent modulo n. n n n n x x, x, x 2, x 3,, x 0 0 0 0 0 g g g g g n Any other solution x x t 0 g Why? is congruent to one of these in the list modulo n. We can show this by using the Division Algorithm on integers t and g. The Division Algorithm (.7) of chapter : Let a, b be given. Then there are unique integers q and r such that a bq r 0 r b Applying this on the above integers t and g means there are integers q and r such that: t gq r 0 r g ( ) n Substituting this t gq r into x x t 0 g gives n n x x 0 t x 0 gq r g g x nq r n 0 g n x 0 0 r Because g nq0 mod n n x r 0 mod n g
Chapter 3: Theory of Modular Arithmetic 33 From ( ) we have 0 r g which means r 0,, 2, 3,, g so this n x x t 0 g is in the above list (*) which is: n n n n x x, x, x 2, x 3,, x 0 0 0 0 0 g g g g g Hence we have exactly g incongruent solutions to ax b mod n. C3 Solving Linear Congruence Equations The list (*) produced in the proof of the above Proposition (3.6) is used to find the g solutions of ax b mod n. Hence the following integers: g g g g n n n n (3.7) x x, x, 2, 3,, 0 0 x x x 0 0 0 g mod n are the g solutions of ax b mod n provided g b where g gcd a, n These numbers can be written in compact form as: g (3.8) x n x t 0 mod n for t 0,, 2,, g. Example 4 Find all the solutions of the linear congruence equation: 7 x 35 mod 70 First we determine the greatest common divisor, gcd, of 7 and 70: gcd 7, 70 7 What next? We need to check that 7 divides into 35. Since 7 Why? Because by the above Proposition (3.6): 35 we have 7 incongruent solutions. mod has exactly g solutions provided g b where g gcd a, n ax b n We can find the first solution by trial and error. Is there an obvious solution? Yes, it is x 5 mod 70 because 7 5 35.
Chapter 3: Theory of Modular Arithmetic 34 How do we find the other six solutions? Using the list of numbers given in (3.8): g (3.8) x n x t 0 mod n With x 5 0 mod 70, n 70 and g 7 numbers 5 0 mod 70 for t 0,, 2,, g we have n x, t 0,, 2,, 7 and 0 g n g 70 0. Substituting these 7 into this (3.8) gives x 5, 5 0, 5 2 0, 5 3 0,, 5 7 0 5, 5, 25, 35, 45, 55, 65 mod 70 Simplifying You can check that each of these is a solution by substituting these into 7 x 35 mod 70 Example 5 Find all the solutions of the linear congruence equation: First gcd7, 70 7 7 x 34 mod 70 the solutions of 7x 34 mod 70? but 7 does not divide into 34. What does this mean in relation to There are no solutions because by Proposition (3.5) which says: mod has a solution g b where g gcd a, n ax b n Hence there are no solutions to 7x 34 mod 70.. Example 6 Find all the incongruent solutions of the linear congruence: 5 x 34 mod 7 The greatest common divisor of 5 and 7 is, that is gcd5, 7 34. How many solutions do we have of the given linear congruence? and divides into One solution which means this linear congruence has a unique solution. How can we find this?
Chapter 3: Theory of Modular Arithmetic 35 We are given 5x 34 mod 7. We can simplify this to make the arithmetic easier; note that 34 6 mod 7 therefore 5x 34 6 mod 7. It is simpler to solve 5x 6 mod 7 rather than 5x 34 mod 7 Also note that 5 2 mod 7 and 6 mod 7 can solve the equivalent easier equation:. Using these results means that we 2x mod 7 2x mod 7 Multiplying by By observation we know x 4 mod 7 is a solution because 2 4 8 mod 4 Checking that this solution is correct: 54 20 6 34 mod 7 Therefore 5x 34 mod 7 has the unique solution 4 mod 7 x., To solve the linear equation 6x 5 0 It is easier to divide through by 3 and solve 2x 5 0. Can we divide through by a common factor for congruences? We need to be careful because we are dealing with integers. The next example demonstrates this. Example 7 Find all the incongruent solutions of the linear congruence: 6 x 5 mod 2 The gcd6, 2 3 and 3 5 so there are 3 incongruent solutions modulo 2. If you only have paper and pen then modulo 2 is too tedious to work with. Can we convert this to a smaller modulus and work with that? Yes. By Proposition (3.0) of the previous section: ac bc mod n implies a b mod n g where g gcd c, n This n g gives us a smaller modulus. We are given 6x 5 mod 2 gcd 6, 2 3 and. We can write the given linear congruence 6x 5 mod 2 as
Chapter 3: Theory of Modular Arithmetic 36 32x 35 mod 7 3 The above Proposition (3.0) allows us to cancel the 3 s which in this case gives: 2 x 5 mod 7 By inspection we have the solution x 6 mod 7 From this x 6 mod 7 we have What are values of k? x 6 7k where k is an integer to this congruence. Since we only have 3 solutions so k 0, and 2. By substituting these values k 0, and 2 into x 6 7k we have x 6, 3, 20 mod 2 These are the 3 incongruent solutions modulo 2. You can check these by substituting them into the given linear congruence 6x 5 mod 2. It is generally easier to divide through by the gcd a, n to find possible solutions of ax b mod n work with. because then we are dealing with a smaller modulus which is easier to C4 Unique s How many solutions does the general linear congruence have if gcd a, n? ax b mod n Just one, a unique solution because g is the number of solutions of ax b mod n provided g divides b. We can write this as a general result. Corollary (3.9). If gcd a, n then the linear congruence ax b mod n has a unique solution modulo n. Proof. Applying Proposition (3.6) with g :
Chapter 3: Theory of Modular Arithmetic 37 ax b mod n has exactly g solutions provided g b where g gcd a, n We are given g gcd a, n and b so we have a unique solution to ax b mod n. Example 8 Solve the linear congruence: Since gcd6, 3 6 x mod 3 6 x mod 3 so we have a unique solution modulo 3. The congruence means that 3k 6x 3k implies x where k is an integer 6 35 We choose k so that x is an integer. Let k 5 then x. Hence 6 In ordinary algebra when we have 6x x mod 3 x. This 6 x is the inverse of 6. 6 Similarly the unique solution of the above linear congruence 6x mod 3 x mod 3 We call this x mod 3 the (multiplicative) inverse of 6 modulo 3. C5 Multiplicative Inverse is Definition (3.20). If ax mod n then the unique solution of this congruence is called the multiplicative inverse of a modulo n and is denoted by a mod n In Example 0 we had 2x mod 5 x 3 mod 5 Therefore we write this in compact notation as 2 3 mod 5..
Chapter 3: Theory of Modular Arithmetic 38 In the exercises we will show that a mod n has an inverse a and n are relatively prime. Example 9 Determine the inverse of 3 mod 4 To find the inverse means we need to solve 3x mod 4. By inspection x 5 mod 4 Because 3 5 5 mod 4 Inverse of 3 modulo 4 is 5 modulo 4 or in notation form 3 5 mod 4.. Example 20 Determine the inverse of 3 modulo 5. In this case we need to solve 3x mod 5. Note that the not divide into so there are no solutions to this congruence 3x mod 5. Therefore 3 modulo 5 has no inverse. gcd 3, 5 3 but 3 does It is critical that a mod n has an inverse if and only if a and n are relatively prime. This implies that only the relative prime integers to n have inverses. Which integers have inverses modulo 0?, 3, 7 and 9 The integers 2, 4, 5, 6, 8 and 0 will not have inverses modulo 0 because they are not relatively prime with 0. SUMMARY (3.5) ax b mod n has solutions g b where g gcd a, n. The multiplicative inverse of a modulo n is the unique solution x mod n of ax mod n and is denoted by a mod n.