Skip to main content

Section 8.4 Modular Arithmetic

In the last section we saw that congruence mod n is an equivalence relation. In this section we will explore this relation in more detail. We will also introduce the concept of modular arithmetic.
Recall the definition for congruence mod n, Definition 8.3.2:
Let a,b,nZ,n>1. Then abmodn if n(ab).
Note, we can use n>1, since n=1, though defined, is not very interesting since 1 divides everything.
In some applications, and often in computer science, the remainder, r, when a is divided by n is denoted r=amodn. When using equals (=), we will mean the specific remainder. When using congruence (), we will mean the relation. For example, 2=12mod5, but many numbers can satisfy the congruence: 1712mod5, etc.

Example 8.4.1. Congruence mod n.

True or false: 195mod2.
Answer 1.
True
True or false: 195mod7.
Answer 2.
True
True or false: 195mod5.
Answer 3.
False
We use modular arithmetic and equivalence mod n when we want to think about remainders when dividing by n. A familiar example is clock time. Suppose it is 11 am and you have an appointment in 3 hours. In general, you would not think of your appointment for 14 o’clock. You would think of noon as 0, and get that your appointment is at 2 o’clock. There are many more applications in algebra, cryptography, and computer science where we want to classify integers by their remainders mod n.
The following theorem will be useful in proving statements involving congruence, but also in helping do calculations.

Proof.

When proving several statements are equivalent, we need to be able to get from any one statement to any other.
(1)(2) by definition of congruence.
(4)(5) by definition of mod as the remainder.
(1)(3) is left as an exercise. (See Activity 8.4.2 and Activity 8.4.3.)
We will prove (3)(4).
Assume a=b+kn for some kZ. By the Quotient-Remainder Theorem, a=qn+r with 0r<n. Thus, b+kn=qn+r. Solving for b, we get b=(qk)n+r. But by uniqueness of the remainder, b has remainder r.
Now assume a and b have the same remainder when divided by n. By the Quotient-Remainder Theorem, a=qn+r and b=qn+r. Substituting in for r, a=qn+bqn=b+(qq)n. Since (qq)Z, let k=qq.
The residue of a modulo n is the remainder when a is divided by n. The set {0,1,,n1} forms a complete set of residues mod n.
Although we have seen congruence mod n is an equivalence relation, we formally state it in the following theorem.
For the proof, see Exercise 8.3.9.

Activity 8.4.4.

Find the equivalence classes for congruence mod 5. List several elements of each equivalence class. What do the elements of each congruence class look like?
Hint.
Think about remainders.
Modular arithmetic is just the process of adding, subtracting, and multiplying, where we treat integers with the same remainder mod n, as equivalent. Thus, we can replace any integer with it’s remainder.

Properties of Modular Arithmetic.

If acmodn and bdmodn, then
  • a+bc+dmodn
  • abcdmodn
  • abcdmodn
  • amcmmodn, for mZ+
Basically, we can do regular arithmetic, where we can reduce to remainders, or equivalence classes mod n.

Example 8.4.4. Modular Arithmetic.

Use modular arithmetic to find
10+25mod6.
Answer 1.
104mod6,251mod6,10+254+15mod6
1025mod6.
Answer 2.
1025414mod6
2515mod6.
Answer 3.
251mod6,25151151mod6

Activity 8.4.5.

Find (31+92)mod5 by first reducing 31 and 92 mod 5, then adding.

Activity 8.4.6.

Find (56)21mod5 by first reducing 56 mod 5, then raising to 21.

Activity 8.4.7.

We can write integers using their decimal expansion. For example, we can write 592 as a decimal expansion: (5×100)+(9×10)+2=5×102+9×101+2×100.

(a)

Write 1526 as a similar expansion using powers of 10.

(b)

Find 10 mod 9 and 10n mod 9 for any nZ,n0.

(c)

Use the decimal expansion and (b) find (592 mod 9) and (1526 mod 9).
If we are doing modular arithmetic we often work directly with the equivalence classes, rather than all of the integers.
We define Zn={0,1,,n1}, where kZn represents the equivalence class [k]. Although this sounds complicated, we just do regular arithmetic with 1,,n1 and reduce to the remainder mod n.

Reading Questions Check Your Understanding

1.

    True or false: 472mod5.
  • True.

  • False.

2.

    True or false: 450mod5.
  • True.

  • False.

3.

    True or false: 41mod5.
  • True.

  • False.

4.

    True or false: 141mod5.
  • True.

  • False.

5.

    True or false: 47+452mod5.
  • True.

  • False.

6.

    True or false: (47)24mod5.
  • True.

  • False.

7.

    True or false: 45001mod5.
  • True.

  • False.

8.

    True or false: 101mod9.
  • True.

  • False.

9.

    True or false: 1021mod9.
  • True.

  • False.

10.

    True or false: 1051mod9.
  • True.

  • False.

11.

    True or false: 10n1mod9.
  • True.

  • False.

12.

Give the equivalence classes for abmod5.
Hint.
There should be 5 equivalence classes. You only need to give a representative for each class in the form [a].

Exercises Exercises

1.

Let a=25 and b=19.
  1. Use the definition of congruence modulo 3 to explain why 2519mod3.
  2. What value of k has the property that 25=19+3k?
  3. What is the (nonnegative) remainder obtained when 25 is divided by 3? When 19 is divided by 3?

2.

Determine if the following are true or false.
  1. 5814 mod 11.
  2. 4689 mod 13.
  3. 674558 mod 56.
  4. 432981 mod 9.

3.

Verify the following statements by simplifying each expression and using the definition of congruence mod 7.
  1. 1282mod7 and 615mod7
  2. (128+61)(2+5)mod7
  3. (12861)(25)mod7
  4. (12861)(25)mod7
  5. 128222mod7

4.

Prove the transitivity of modular congruence. That is, prove for all a,b,c,nZ with n>1, if abmodn and bcmodn, then acmodn.

5.

Prove for all a,c,nZ with n>1, if acmodn, then a2c2modn.

6.

Prove for all a,c,n,mZ with n>1, and m1, if acmodn, then amcmmodn.
Hint.
Use mathematical induction on m.

7.

Prove for all integers n0, 10n1mod9.

8.

Prove that a positive integer, N is divisible by 9 if and only if the sum of the digits of N is divisible by 9.
Hint.
The previous problem will be helpful, as will writing N as a decimal expansion (see Activity 8.4.7). It can be useful in proving that a number is divisible by 9 to instead show that it is congruent to 0 mod 9. Also note, this is an “if and only if” statement so your proof requires two parts.
You have attempted 1 of 13 activities on this page.