Skip to main content

Section 7.4 Modular Arithmetic

Beginning Activity Beginning Activity 1: Congruence Modulo 6

For this activity, we will only use the relation of congruence modulo 6 on the set of integers.

1.

Find five different integers a such that a3(mod6) and find five different integers b such that b4(mod6). That is, find five different integers in [3], the congruence class of 3 modulo 6 and five different integers in [4], the congruence class of 4 modulo 6.

2.

Calculate s=a+b using several values of a in [3] and several values of b in [4] from Exercise 1. For each sum s that is calculated, find r so that 0r<6 and sr(mod6). What do you observe?

3.

Calculate p=ab using several values of a in [3] and several values of b in [4] from Exercise 1. For each product p that is calculated, find r so that 0r<6 and pr(mod6). What do you observe?

4.

Calculate q=a2 using several values of a in [3] from Exercise 1. For each product q that is calculated, find r so that 0r<6 and qr(mod6). What do you observe?

Beginning Activity Beginning Activity 2: The Remainder When Dividing by 9

If a and b are integers with b>0, then from the Division Algorithm, we know that there exist unique integers q and r such that

a=bq+r and 0r<b.

In this activity, we are interested in the remainder r. Notice that r=abq. So, given a and b, if we can calculate q, then we can calculate r.

We can use the “int” function on a calculator to calculate q. [The “int” function is the “greatest integer function.” If x is a real number, then int(x) is the greatest integer that is less than or equal to x.]

So, in the context of the Division Algorithm, q=int(ab). Consequently,

r=abint(ab).

If n is a positive integer, we will let s(n) denote the sum of the digits of n. For example, if n=731, then

s(731)=7+3+1=11.

For each of the following values of n, calculate

  • The remainder when n is divided by 9, and

  • The value of s(n) and the remainder when s(n) is divided by 9.

What do you observe?

Subsection The Integers Modulo n

Let nN. Since the relation of congruence modulo n is an equivalence relation on Z, we can discuss its equivalence classes. Recall that in this situation, we refer to the equivalence classes as congruence classes.

Definition.

Let nN. The set of congruence classes for the relation of congruence modulo n on Z is the set of integers modulo n, or the set of integers mod n. We will denote this set of congruence classes by Zn.

Corollary 7.21 tells us that

Z=[0][1][2][n1].

In addition, we know that each integer is congruent to precisely one of the integers 0,1,2,,n1. This tells us that one way to represent Zn is

Zn={[0],[1],[2],,[n1]}.

Consequently, even though each integer has a congruence class, the set Zn has only n distinct congruence classes.

The set of integers Z is more than a set. We can add and multiply integers. That is, there are the arithmetic operations of addition and multiplication on the set Z, and we know that Z is closed with respect to these two operations.

One of the basic problems dealt with in modern algebra is to determine if the arithmetic operations on one set “transfer” to a related set. In this case, the related set is Zn. For example, in the integers modulo 5, Z5, is it possible to add the congruence classes [4] and [2] as follows?

[2]=[4+2]=[6]=[1].

We have used the symbol to denote addition in Z5 so that we do not confuse it with addition in Z. This looks simple enough, but there is a problem. The congruence classes [4] and [2] are not numbers, they are infinite sets. We have to make sure that we get the same answer no matter what element of [4] we use and no matter what element of [2] we use. For example,

94(mod5) and so [9]=[4]. Also, 72(mod5) and so [7]=[2].

Do we get the same result if we add [9] and [7] in the way we did when we added [4] and [2]? The following computation confirms that we do:

[7]=[9+7]=[16]=[1].

This is one of the ideas that was explored in Beginning Activity 1. The main difference is that in this activity, we used the relation of congruence, and here we are using congruence classes. All of the examples in Beginning Activity 1 should have illustrated the properties of congruence modulo 6 in the following table. The left side shows the properties in terms of the congruence relation and the right side shows the properties in terms of the congruence classes.

If a3(mod6) and b4(mod6), then

  • (a+b)(3+4)(mod6);

  • (ab)(34)(mod6).

If [a]=[3] and [b]=[4] in Z6, then

  • [a+b]=[3+4];

  • [ab]=[34].

These are illustrations of general properties that we have already proved in Theorem 3.34. We repeat the statement of the theorem here because it is so important for defining the operations of addition and multiplication in Zn.

Theorem 3.34 Restated.

Let n be a natural number and let a,b,c, and d be integers. Then

  1. If ab(modn) and cd(modn), then (a+c)(b+d)(modn).

  2. If ab(modn) and cd(modn), then acbd(modn).

  3. If ab(modn) and mN, then ambm(modn).

Since xy(modn) if and only if [x]=[y], we can restate the result of this Theorem 3.34 in terms of congruence classes in Zn.

Because of Corollary 7.24, we know that the following formal definition of addition and multiplication of congruence classes in Zn is independent of the choice of the elements we choose from each class. We say that these definitions of addition and multiplication are well defined.

Definition.

Let nN. Addition and multiplication in Zn are defined as follows: For [a],[c]Zn,

[a][c]=[a+c] and [a][c]=[ac].

The term modular arithmetic is used to refer to the operations of addition and multiplication of congruence classes in the integers modulo n.

So if nN, then we have an addition and multiplication defined on Zn, the integers modulo n.

Always remember that for each of the equations in the definitions, the operations on the left,  and , are the new operations that are being defined. The operations on the right side of the equations (+ and ) are the known operations of addition and multiplication in Z.

Since Zn is a finite set, it is possible to construct addition and multiplication tables for Zn. In constructing these tables, we follow the convention that all sums and products should be in the form [r], where 0r<n. For example, in Z3, we see that by the definition, [1][2]=[3], but since 30(mod3), we see that [3]=[0] and so we write

[1][2]=[3]=[0].

Similarly, by definition, [2][2]=[4], and in Z3, [4]=[1]. So we write

[2][2]=[4]=[1].

The complete addition and multiplication tables for Z3 are

[0] [1] [2]
[0] [0] [1] [2]
[1] [1] [2] [0]
[2] [2] [0] [1]
[0] [1] [2]
[0] [0] [0] [0]
[1] [0] [1] [2]
[2] [0] [2] [1]

Progress Check 7.25. Modular Arithmetic in Z2, Z5, and Z6.

(a)

Construct addition and multiplication tables for Z2, the integers modulo 2.

Solution.

[0] [1]
[0] [0] [1]
[1] [1] [0]
[0] [1]
[0] [0] [0]
[1] [0] [1]

(b)

Verify that the following addition and multiplication tables for Z5 are correct.

[0] [1] [2] [3] [4]
[0] [0] [1] [2] [3] [4]
[1] [1] [2] [3] [4] [0]
[2] [2] [3] [4] [0] [1]
[3] [3] [4] [0] [1] [2]
[4] [4] [0] [1] [2] [3]
[0] [1] [2] [3] [4]
[0] [0] [0] [0] [0] [0]
[1] [0] [1] [2] [3] [4]
[2] [0] [2] [4] [1] [3]
[3] [0] [3] [1] [4] [2]
[4] [0] [4] [3] [2] [1]

(c)

Construct complete addition and multiplication tables for Z6.

Solution.

[0] [1] [2] [3] [4] [5]
[0] [0] [1] [2] [3] [4] [5]
[1] [1] [2] [3] [4] [5] [0]
[2] [2] [3] [4] [5] [0] [1]
[3] [3] [4] [5] [0] [1] [2]
[4] [4] [5] [0] [1] [2] [3]
[5] [5] [0] [1] [2] [3] [4]
[0] [1] [2] [3] [4] [5]
[0] [0] [0] [0] [0] [0] [0]
[1] [0] [1] [2] [3] [4] [5]
[2] [0] [2] [4] [0] [2] [4]
[3] [0] [3] [0] [3] [0] [3]
[4] [0] [4] [2] [0] [4] [2]
[5] [0] [5] [4] [3] [2] [1]

(d)

In the integers, the following statement is true. We sometimes call this the zero product property for the integers.

For all a,bZ, if ab=0, then a=0 or b=0.
Write the contrapositive of the conditional statement in this property.

Solution.

For all a,bZ, if a0 and b0, then ab0.

(e)

Are the following statements true or false? Justify your conclusions.

(i)

For all [a],[b]Z5, if [a][b]=[0], then [a]=[0] or [b]=[0].

Solution.

The statement in (i) is true.

(ii)

For all [a],[b]Z6, if [a][b]=[0], then [a]=[0] or [b]=[0].

Solution.

The statement in (ii) is false. For example, in Z6, [2][3]=[0].

Subsection Divisibility Tests

Congruence arithmetic can be used to prove certain divisibility tests. For example, you may have learned that a natural number is divisible by 9 if the sum of its digits is divisible by 9. As an easy example, note that the sum of the digits of 5823 is equal to 5+8+2+3=18, and we know that 18 is divisible by 9. It can also be verified that 5823 is divisible by 9. (The quotient is 647.) We can actually generalize this property by dealing with remainders when a natural number is divided by 9.

Let nN and let s(n) denote the sum of the digits of n. For example, if n=7319, then s(7319)=7+3+1+9=20. In Beginning Activity 2, we saw that

73192(mod9) and 202(mod9).

In fact, for every example in Beginning Activity 2, we saw that n and s(n) were congruent modulo 9 since they both had the same remainder when divided by 9. The concepts of congruence and congruence classes can help prove that this is always true.

We will use the case of n=7319 to illustrate the general process. We must use our standard place value system. By this, we mean that we will write 7319 as follows:

(63)7319=(7×103)+(3×102)+(1×101)+(9×100).

The idea is to now use the definition of addition and multiplication in Z9 to convert equation (1) to an equation in Z9. We do this as follows:

=[(7×103)+(3×102)+(1×101)+(9×100)]=[7×103][3×102][1×101][9×100](64)=([7][103])([3][102])([1][101])([9][1])

Since 1031(mod9), 1021(mod9) and 101(mod9), we can conclude that [103]=[1], [102]=[1] and [10]=[1]. Hence, we can use these facts and equation (64) to obtain

[7319]=([7][103])([3][102])([1][10])([9][1])=([7][1])([3][1])([1][1])([9][1])=[7][3][1][9](65)=[7+3+1+9]

Equation (65) tells us that 7319 has the same remainder when divided by 9 as the sum of its digits. It is easy to check that the sum of the digits is 20 and hence has a remainder of 2. This means that when 7319 is divided by 9, the remainder is 2.

To prove that any natural number has the same remainder when divided by 9 as the sum of its digits, it is helpful to introduce notation for the decimal representation of a natural number. The notation we will use is similar to the notation for the number 7319 in equation (63).

In general, if nN, and n=akak1a1a0 is the decimal representation of n, then

n=(ak×10k)+(ak1×10k1)++(a1×101)+(a0×100).

This can also be written using summation notation as follows:

n=j=0k(aj×10j).

Using congruence classes for congruence modulo 9, we have

=[(ak×10k)+(ak1×10k1)++(a1×101)+(a0×100)]=[ak×10k][ak1×10k1][a1×101][a0×100]=([ak][10k])([ak1][10k1])(66)([a1][101])([a0][100])

One last detail is needed. It is given in Proposition 7.26. The proof by mathematical induction is Exercise 6.

If we let s(n) denote the sum of the digits of n, then

s(n)=ak+ak1++a1+a0,

Now using equation (66) and Proposition 7.26, we obtain

[n]=([ak][1])([ak1][1])([a1][1])([a0][1])=[ak][ak1][a1][a0]=[ak+ak1++a1+a0].=[s(n)].

This completes the proof of Theorem 7.27.

Item 3 of Theorem 7.27 is called a divisibility test. If gives a necessary and sufficient condition for a natural number to be divisible by 9. Other divisibility tests will be explored in the exercises. Most of these divisibility tests can be proved in a manner similar to the proof of the divisibility test for 9.

Exercises Exercises

1.

Complete the addition and multiplication tables for the following.

(a)

Z4.

Answer.

[0] [1] [2] [3]
[0] [0] [1] [2] [3]
[1] [1] [2] [3] [0]
[2] [2] [3] [0] [1]
[3] [3] [0] [1] [2]

[0] [1] [2] [3]
[0] [0] [0] [0] [0]
[1] [0] [1] [2] [3]
[2] [0] [2] [0] [2]
[3] [0] [3] [2] [1]

(b)

Z7.

Answer.

[0] [1] [2] [3] [4] [5] [6]
[0] [0] [1] [2] [3] [4] [5] [6]
[1] [1] [2] [3] [4] [5] [6] [0]
[2] [2] [3] [4] [5] [6] [0] [1]
[3] [3] [4] [5] [6] [0] [1] [2]
[4] [4] [5] [6] [0] [1] [2] [3]
[5] [5] [6] [0] [1] [2] [3] [4]
[6] [6] [0] [1] [2] [3] [4] [5]

[0] [1] [2] [3] [4] [5] [6]
[0] [0] [0] [0] [0] [0] [0] [0]
[1] [0] [1] [2] [3] [4] [5] [6]
[2] [0] [2] [4] [6] [1] [3] [5]
[3] [0] [3] [6] [2] [5] [1] [4]
[4] [0] [4] [1] [5] [2] [6] [3]
[5] [0] [5] [3] [1] [6] [4] [2]
[6] [0] [6] [5] [4] [3] [2] [1]

2.

The set Zn contains n elements. One way to solve an equation in Zn is to substitute each of these n elements in the equation to check which ones are solutions. In Zn, when parentheses are not used, we follow the usual order of operations, which means that multiplications are done first and then additions. Solve each of the following equations:

(b)

[x]2=[1] in Z8

(c)

[x]4=[1] in Z5

(d)

[x]2[3][x]=[3] in Z6

(e)

[x]2[1]=[0] in Z5

Answer.

[x]=[2] or [x]=[3]

(f)

[3][x][2]=[0] in Z5

(g)

[3][x][2]=[0] in Z6

Answer.

The equation has no solution.

(h)

[3][x][2]=[0] in Z9

3.

In each case, determine if the statement is true or false.

(a)

For all [a]Z6, if [a][0], then there exists a [b]Z6 such that [a][b]=[1].

Answer.

The statement is false. By using the multiplication table for Z6, we see that a counterexample is [a]=[2].

(b)

For all [a]Z5, if [a][0], then there exists a [b]Z5 such that [a][b]=[1].

Answer.

The statement is true. By using the multiplication table for Z5, we see that:

[1][1]=[1].[2][3]=[1][3][2]=[1].[4][4]=[1]

4.

In each case, determine if the statement is true or false.

(a)

For all [a],[b]Z6, if [a][0] and [b][0], then [a][b][0].

(b)

For all [a],[b]Z5, if [a][0] and [b][0], then [a][b][0].

5.

Complete the following.

(a)

Prove the following proposition:

For each [a]Z5, if [a][0], then [a]2=[1] or [a]2=[4].

Answer.

The proof consists of the following computations:

[1]2=[1][2]2=[4][3]2=[9]=[4][4]2=[16]=[1]

6.

Use mathematical induction to prove Proposition 7.26.

If n is a nonnegative integer, then 10n1(mod9), and hence for the equivalence relation of congruence modulo 9, [10n]=[1].

7.

Use mathematical induction to prove that if n is a nonnegative integer, then 10n1(mod3). Hence, for congruence classes modulo 3, if n is a nonnegative integer, then [10n]=[1].

8.

Let nN and let s(n) denote the sum of the digits of n. So if we write

n=(ak×10k)+(ak1×10k1)++(a1×101)+(a0×100),

then s(n)=ak+ak1++a1+a0. Use the result in Exercise 7 to help prove each of the following:

(a)

[n]=[s(n)], using congruence classes modulo 3.

(b)

ns(n)(mod3).

(c)

3n if and only if 3s(n).

9.

Use mathematical induction to prove that if n is an integer and n1, then 10n0(mod5). Hence, for congruence classes modulo 5, if n is an integer and n1, then [10n]=[0].

10.

Let nN and assume

n=(ak×10k)+(ak1×10k1)++(a1×101)+(a0×100).

Use the result in Exercise 9 to help prove each of the following:

(a)

[n]=[a0], using congruence classes modulo 5.

(b)

na0(mod5).

(c)

5n if and only if 5a0.

11.

Use mathematical induction to prove that if n is an integer and n2, then 10n0(mod4). Hence, for congruence classes modulo 4, if n is an integer and n2, then [10n]=[0].

12.

Let nN and assume

n=(ak×10k)+(ak1×10k1)++(a1×101)+(a0×100).

Use the result in Exercise 11 to help prove each of the following:

(a)

[n]=[10a1+a0], using congruence classes modulo 4.

(b)

n(10a1+a0)(mod4).

(c)

4n if and only if 4(10a1+a0).

13.

Use mathematical induction to prove that if n is an integer and n3, then 10n0(mod8). Hence, for congruence classes modulo 8, if n is an integer and n3, then [10n]=[0].

14.

Let nN and assume

n=(ak×10k)+(ak1×10k1)++(a1×101)+(a0×100).

Use the result in Exercise 13 to help develop a divisibility test for 8. Prove that your divisibility test is correct.

15.

Use mathematical induction to prove that if n is a nonnegative integer then 10n(1)n(mod11). Hence, for congruence classes modulo 11, if n is a nonnegative integer, then [10n]=[(1)n].

16.

Let nN and assume

n=(ak×10k)+(ak1×10k1)++(a1×101)+(a0×100).

Use the result in Exercise 15 to help prove each of the following:

(a)

nj=0k(1)jaj(mod11).

(b)

[n]=[j=0k(1)jaj], using congruence classes modulo 11.

(c)

11 divides n if and only if 11 divides j=0k(1)jaj.

17.

Prove the following propositions.

(a)

For all [a],[b]Z3, if [a]2+[b]2=[0], then [a]=0 and [b]=[0].

Answer.

Prove the contrapositive by calculating [a]2+[b]2 for all nonzero [a] and [b] in Z3.

(b)

Let a,bZ. If (a2+b2)0(mod3), then a0(mod3) and b0(mod3).

(Use Task 17.a.)

(c)

For all a,bZ, if 3 divides (a2+b2), then 3 divides a and 3 divides b.

(Use Task 17.b.)

18.

Prove the following proposition:

For each aZ, if there exist integers b and c such that a=b4+c4, then the units digit of a must be 0, 1, 2, 5, 6, or 7.

19.

Is the following proposition true or false? Justify your conclusion.

Let nZ. If n is odd, then 8(n21).

Hint.

What are the possible values of n (mod 8)?

20.

Prove the following proposition:

Let nN. If n7(mod8), then n is not the sum of three squares. That is, there do not exist natural numbers a, b, and c such that n=a2+b2+c2.

Activity 46. Using Congruence Modulo 4.

The set Zn is a finite set, and hence one way to prove things about Zn is to simply use the n elements in Zn as the n cases for a proof using cases. For example, if nZ, then in Z4, [n]=[0], [n]=[1], [n]=[2], or [n]=[3].

(a)

Prove that if nZ, then in Z4, [n]2=[0] or [n]2=[1]. Use this to conclude that in Z4, [n2]=[0] or [n2]=[1].

(b)

Translate the equations [n2]=[0] and [n2]=[1] in Z4 into congruences modulo 4.

(c)

Use a result in Exercise 12 to determine the value of r so that rZ, 0r<3, and

104 257 833 259r(mod4).

That is, [104 257 833 259]=[r] in Z4.

(d)

Is the natural number 104 257 833 259 a perfect square? Justify your conclusion.