Number systems

This free course is available to start right now. Review the full course description and key learning outcomes and create an account and enrol if you want a free statement of participation.

Free course

# 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 ×nb = b ×na = 1. These equations can also be written as abba ≡ 1 (mod n). We denote the multiplicative inverse b of a by a1, 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.

### 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 non-zero 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.

### 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 left-hand 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 left-hand 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.

### 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 rm is a factor of rm−1, and thus the penultimate equation shows that rm is a factor of rm−2, and so on. Continuing in this way, we find that rm 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 rm = 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 ×na = 1.

It is possible that d does not belong to n, but in that case db for some b n, where b ≠ 0, so we also have b ×na = 1.

Hence a has a multiplicative inverse b in n; we write b = a1 (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 ×na = 1. Then ba = kn + 1 for some integer k, so bakn = 1.

If a and n have a common factor c, say, then c is a factor of bakn 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 non-zero element in p has a multiplicative inverse in p.

Proof

If p is prime, then every non-zero 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 ×pa−1 = a−1 ×pa = 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 a1 and we can solve Equation 3.3 by multiplying both sides by this inverse.

## Example 13

Solve the equation 10 ×27x = 14.

### 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 ×nc.

(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 ×16x = 3

• (b)  8 ×51x = 19

### 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 ×12x =7.

### 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 ×12x = 6

• (b)  4 ×12x = 8

### 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 ×12x = 6,   8 ×12x = 7,   5 ×12x = 2.

• (b)  In 16: 4 ×16x = 12,   3 ×16x = 13,   8 ×16x = 2.

### Solution

• (a)  One solution of the equation 3 ×12x = 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 ×12x = 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 ×12x = 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 ×16x =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 ×16x = 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 ×16x = 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 ×9x = 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.

### 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 ×8x = 4.

• (b)  Find all the values of c in 8 for which it is possible to solve the equation x ×8x = c.

### Solution

We find all the values of x ×8x.

• (a)  The solutions of x ×8x = 4 are x = 2 and x = 6.

• (b)  The equation x ×8x = 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.

M208_6