3.4 Modular multiplication
In the last subsection we stated that, for any integer n ≥ 2, the set _{n} satisfies the same rules for addition modulo n as the real numbers satisfy for ordinary addition. When it comes to multiplication in _{n}, most of the familiar rules for multiplication of the real numbers are true. In particular, the following properties hold.
The following property also holds.
These properties can be proved in a similar way to the additive properties. You will notice that one property is missing from the list of multiplicative properties; namely, the multiplicative inverse property M3.
We say that b is the multiplicative inverse of a in _{n} if a, b _{n} and a ×_{n}b = b ×_{n}a = 1. These equations can also be written as ab ≡ ba ≡ 1 (mod n). We denote the multiplicative inverse b of a by a^{−}^{1}, when it exists, and it may be referred to as the multiplicative inverse of a modulo n. We now investigate the existence of multiplicative inverses.
(For example, from the table for _{7} below, 3 ×_{7} 5 = 5 ×_{7} 3 = 1, so 5 is the multiplicative inverse of 3 in _{7}.)
Here are the multiplication tables for _{4} and _{7}.
Exercise 46

(a) Use the tables above to answer the following.
(i) Which integers in _{4} have multiplicative inverses?
(ii) Find the multiplicative inverse of every integer in _{7} except 0.
(b) Construct a multiplication table for _{10}, and decide which integers in _{10} have multiplicative inverses.
Answer
Solution

(a)
(i) 1 and 3 have multiplicative inverses in _{4}, since 1 ×_{4} 1 = 1 and 3 ×_{4} 3 = 1.
(ii) The multiplicative inverses in _{7} are given by the following table, where b is the multiplicative inverse of a.
(b)
The integers 1, 3, 7 and 9 have multiplicative inverses in _{10}.
From the solution to Exercise 46, it is clear that, unlike and , some systems _{n} contain nonzero elements that do not have a multiplicative inverse. The question of whether an element a _{n} has a multiplicative inverse in _{n} is connected with the common factors of a and n.
Definitions
Two positive integers a and b have a common factor c, where c is a positive integer, if a and b are both divisible by c.
Two positive integers a and b are said to be coprime, or relatively prime, if their only common factor is 1.
(The greatest common factor of a and b is the largest of their common factors.)
Later in this subsection we prove that an element a of _{n} has a multiplicative inverse in _{n} if and only if a and n are coprime. First we look at a method for finding multiplicative inverses where they exist. Although we can find such inverses by trial and error, or by writing out the multiplication table for _{n}, as n becomes larger the method illustrated in the following example becomes more efficient. It is known as Euclid's Algorithm, and was described in Euclid's Elements, which dates from around 300 BC. (Euclid did not express the algorithm in this form, however.)
Example 12
Find the multiplicative inverse of 10 in _{27}.
Answer
Solution
We apply the Division Algorithm repeatedly, starting by dividing the modulus 27 by the integer 10, whose multiplicative inverse we seek:
Note: The first part of the method, consisting of repeated application of the Division Algorithm, is the procedure known as Euclid's Algorithm. When it is applied to any two positive integers a and b, the last but one remainder is the greatest common factor of a and b. The second part of the method, which involves starting with the last but one equation from the first part, is often described as working backwards through Euclid's Algorithm.
At each step we divide the divisor in the row above by the remainder in the row above, repeating the process until we reach a remainder of 0 (which must occur because the remainders decrease by at least 1 at each step).
Now we use Equations 3.1 to find the required multiplicative inverse. Starting with the last but one equation, and working upwards, we have
(We rearrange each equation so that only the remainder is on the lefthand side.)
We write down the first of Equations 3.2, and use the other two equations to eliminate multiples of 3 and 7 by successive substitutions.
(The multiples may be negative; for example, −8 × 10 is a multiple of 10.)
After each substitution, 1 is expressed as a multiple of one integer plus a multiple of another integer, where the two integers are a neighbouring pair from the list 27, 10, 7, 3 of lefthand sides of Equations 3.1. The last equation expresses 1 in terms of multiples of the two integers that we started with, 10 and 27. Rearranging this equation gives
so
Now the integer −8 does not belong to _{27}, but, since −8 ≡ 19 (mod 27), we have
and hence
Hence 19 is the multiplicative inverse of 10 in _{27} and we can write 10^{−1} = 19 (mod 27).
As a check:
Exercise 47
Use Euclid's Algorithm to find
(a) the multiplicative inverse of 7 in _{16};
(b) the multiplicative inverse of 8 in _{51}.
Answer
Solution
(a)
Starting with the last equation, we have
Hence 7 × 7 = 3 × 16 + 1, so 7 ×_{16} 7 = 1 and the multiplicative inverse of 7 in _{16} is 7.
(b)
Starting with the last equation, we have
Hence (−19) × 8 ≡ 1 (mod 51), so
Hence 32 ×_{51} 8 = 1 and the multiplicative inverse of 8 in _{51} is 32.
We now use Euclid's Algorithm to prove our main result.
Theorem 6
Let n and a be positive integers, with a in _{n}. Then a has a multiplicative inverse in _{n} if and only if a and n are coprime.
Proof
First we prove the ‘if’ part; that is, a has a multiplicative inverse in _{n} if a and n are coprime.
We use Euclid's Algorithm repeatedly and show that, if a and n are coprime, then the final remainder before we reach 0 must be 1.
Let
Since the remainders decrease by at least 1 with each step, they must eventually reach 0.
The final equation shows that r_{m} is a factor of r_{m}_{−1}, and thus the penultimate equation shows that r_{m} is a factor of r_{m}_{−2}, and so on. Continuing in this way, we find that r_{m} is a factor of all the remainders, and so of both a and n. Since a and n were assumed to be coprime, we deduce that r_{m} = 1.
Therefore we have, from the penultimate equation,
and, by successively substituting for the remainders, we find that there are integers k and d such that 1 = kn + da. Hence da = −kn + 1, so d ×_{n}a = 1.
It is possible that d does not belong to _{n}, but in that case d ≡ b for some b _{n}, where b ≠ 0, so we also have b ×_{n}a = 1.
Hence a has a multiplicative inverse b in _{n}; we write b = a^{−}^{1} (mod n).
Now we prove the ‘only if ’ part; that is, a has a multiplicative inverse in _{n} only if a and n are coprime.
Suppose that a has a multiplicative inverse in _{n}; that is, there is a number b such that b ×_{n}a = 1. Then ba = kn + 1 for some integer k, so ba − kn = 1.
If a and n have a common factor c, say, then c is a factor of ba − kn and hence of 1. Therefore c can only be 1, so a and n are coprime.
Theorem 6 gives us an important corollary in the case when the modulus n is a prime number.
Corollary
Let p be a prime number. Then every nonzero element in _{p} has a multiplicative inverse in _{p}.
Proof
If p is prime, then every nonzero element in _{p} is coprime with p, and so has a multiplicative inverse in _{p} by Theorem 6.
It follows that if we take multiplication in _{p}, where p is prime, then we can add the following property to the list of properties for multiplication in _{n}:
M3. If a _{p}, and a ≠ 0, then a has a multiplicative inverse a^{−1} _{p}
such that a ×_{p}a^{−1} = a^{−1} ×_{p}a = 1.
But this property does not hold for _{n} if n is not prime, as in that case some elements a _{n} do not have multiplicative inverses.
We now return briefly to the question of whether we can solve equations in modular arithmetic. We begin by considering linear equations, that is, equations of the form
where a, c _{n}. We seek all solutions x _{n}.
First we consider the case where a and n are coprime. In this case, by Theorem 6, a has a multiplicative inverse a^{−}^{1} and we can solve Equation 3.3 by multiplying both sides by this inverse.
Example 13
Solve the equation 10 ×_{27}x = 14.
Answer
Solution
In Example 12 we found that the multiplicative inverse of 10 in _{27} is 19. Hence we have
so the given equation has the unique solution x = 23.
In general, by an argument similar to that of Example 13, if a and n are coprime, then Equation 3.3 has the unique solution x = a^{−1} ×_{n}c.
(In particular, if a and n are coprime, then Equation 3.3 has a solution for every c _{n}, so every element of _{n} appears in the row labelled a of the multiplication table for _{n}.)
Exercise 48
Use the method of Example 13 and the solution to Exercise 47 to solve the following equations.
(a) 7 ×_{16}x = 3
(b) 8 ×_{51}x = 19
Answer
Solution
(a) Since the multiplicative inverse of 7 in _{16} is 7 (see the solution to Exercise 47(a)), we have
(b) Since the multiplicative inverse of 8 in _{51} is 32 (see the solution to Exercise 47(b)), we have
To use the method of Example 13, first we need to find the multiplicative inverse in _{n} of the coefficient a of x. If we have not already found this inverse (for example, by using Euclid's Algorithm), and the modulus n is fairly small, then the quickest way to solve the equation may be just to try different values of x. We know that there is a unique solution, so we can stop trying values once we have found a solution. Sometimes a solution can be spotted by using conguences.
Example 14
Solve the equation 5 ×_{12}x =7.
Answer
Solution
Observe that 7 ≡ −5 (mod 12), so we have
The integer −1 is not an element of _{12}, but −1 ≡ 11 (mod 12), so
Hence the solution of the given equation is x = 11.
Now consider Equation 3.3 in the case where a and n are not coprime: suppose that a and n have a common factor d ≥ 2. Then Equation 3.3 has a solution only if d is also a factor of c. To see this, notice that Equation 3.3 is equivalent to
(Thus if a and n have a common factor d ≥ 2, then all the elements in the row labelled a of the multiplication table for _{n} have common factor d.)
If there exists an integer solution x = b of this equation, then
and, since d is a factor of both a and n, it follows that d is a factor of c.
If a, n and c have a common factor d ≥ 2, then Equation 3.3 has more than one solution. In fact, although we do not prove it here, if d is the greatest common factor of a, n and c, then Equation 3.3 has d solutions, given by
where x = b is the smallest solution. That is, we add multiples of n/d to the smallest solution.
Note: You can prove that these are solutions by using substitution. For example, x = b + n/d is a solution because
where the last but one line follows because x = b is a solution and a/d _{n}.
There is a method for finding the smallest solution which is similar to the method used in Example 13 for the case where a and n are coprime, but we do not cover it in this course. If n is fairly small, then we can find the smallest solution by trying values. Alternatively, it may be possible to spot a solution, but as this may not be the smallest solution, we may need to subtract multiples of n/d as well as, or instead of, adding them.
Example 15
Solve each of the following equations.
(a) 4 ×_{12}x = 6
(b) 4 ×_{12}x = 8
Answer
Solution
(a) This equation has no solutions, since 4 is a factor of both 4 and 12 but is not a factor of 6.
(b) One solution of this equation is x = 2. Also n/d = 12/4 = 3, so the other solutions are x = 2 + 3 = 5 and x = 2 + 2 × 3 = 8.
Exercise 49
Find all the solutions of the following equations.
(a) In _{12}: 3 ×_{12}x = 6, 8 ×_{12}x = 7, 5 ×_{12}x = 2.
(b) In _{16}: 4 ×_{16}x = 12, 3 ×_{16}x = 13, 8 ×_{16}x = 2.
Answer
Solution
(a) One solution of the equation 3 ×_{12}x = 6 is x = 2. Also n/d = 12/3 = 4, so the other solutions are x = 2 + 4 = 6 and x = 2 + 2 × 4 = 10.
The equation 8 ×_{12}x = 7 has no solutions because 8 and 12 have common factor 4 but 7 does not.
Because 5 and 12 are coprime, the equation 5 ×_{12}x = 2 has a unique solution. The solution, x = 10, can be found in various ways: for example, by calculating x = 5^{−1} ×_{12} 2, or by testing possible values for x, or by spotting that 2 ≡ −10 (mod 12) and using the fact that the congruence 5 × (−2) ≡ −10 (mod 12) implies 5 × 10 ≡ 2 (mod 12) giving 5 ×_{12} 10 = 2.
(b) One solution of the equation 4 ×_{16}x =12 is x = 3. Also n/d = 16/4 = 4, so the other solutions are x = 3 + 4 = 7, x =3 + 8 = 11 and x = 3 + 12 = 15.
Because 3 and 16 are coprime, the equation 3 ×_{16}x = 13 has a unique solution. The solution, x = 15, can be found in various ways: for example, by calculating x = 3^{−1} ×_{16} 13, or by testing possible values for x, or by spotting that 13 ≡ −3 (mod 16) and using the fact that the congruence 3 × (−1) ≡ −3 (mod 16) implies 3 × 15 ≡ 13 (mod 16) giving 3 ×_{16} 15 = 13.
The equation 8 ×_{16}x = 2 has no solutions because 8 and 16 have common factor 4 but 2 does not.
Near the beginning of Section 3.3 we posed the question: can we solve the equation x ×_{9}x = 2? That is, is there an element of _{9} whose square 2?
Example 16
Show that there is no element of _{9} whose square is 2.
Answer
Solution
We solve this problem by exhaustion, by writing down the squares of all the elements of _{9}.
We can see from this table that there is no element of _{9} whose square is 2. In fact, we can go further and say that the remainder of a square modulo 9 can be only 0, 1, 4 or 7. That is, 0, 1, 4 and 7 are the only elements of _{9} that are squares of other elements.
Exercise 50
(a) Find all the solutions of the equation x ×_{8}x = 4.
(b) Find all the values of c in _{8} for which it is possible to solve the equation x ×_{8}x = c.
Answer
Solution
We find all the values of x ×_{8}x.
(a) The solutions of x ×_{8}x = 4 are x = 2 and x = 6.
(b) The equation x ×_{8}x = c can be solved for c = 0, 1, 4.
In general, the solution of quadratic equations in modular arithmetic is more complicated than that of linear equations. You will study this topic further if you take a course in number theory.