Modular Arithmetic

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

2-9-2018

Modular Arithmetic
Modular arithmetic is a way of systematically ignoring differences involving a multiple of an integer.
If n is an integer, two integers are equal mod n if they differ by a multiple of n; it is as if multiples of n are
“set equal to 0”.

Definition. Let n, x, and y be integers. x is congruent to y mod n if n | x − y. Notation:

x = y (mod n) .

Remarks. n | x − y is equivalent to the following statements:

(a) n | y − x.

(b) x = y + jn for some j ∈ Z.

(c) y = x + kn for some k ∈ Z.

I’ll often use any of these four statements as the definition of x = y (mod n).

A lot of people like to write “x ∼


= y (mod n)” instead of “x = y (mod n)”. I don’t think there’s any
harm in using an ordinary equal sign, since the “ (mod n)” makes the meaning clear. It’s also a bit shorter
to write.

Example. (Examples of congruences with numbers) (a) Demonstrate that 7 = 1 (mod 6) and
57 = −13 (mod 7).

(b) Express “x is even” and “x is odd” in terms of congruences.

(c) What does x = 0 (mod n) means in terms of divisibility?

(a)
7 = 1 (mod 6) , since 6 | 7 − 1.
57 = −13 (mod 7) , since 7 | 57 − (−13).
(b) x is even if and only if x = 0 (mod 2) and x is odd if and only if x = 1 (mod 2).
(c) x = 0 (mod n) if and only if n | x. Thus, congruences provide a convenient notation for dealing with
divisibility relations.

The following proposition says that you can work with modular equations in many of the ways that you
work with ordinary equations.

Proposition. Let n ∈ Z.

(a) If a = b (mod n) and c = d (mod n), then

a + c = b + d (mod n) .

(b) If a = b (mod n) and c = d (mod n), then

ac = bd (mod n) .

1
(c) If a = b (mod n), then
ac = bc (mod n) .
Proof. Two ideas for these kinds of proofs:
1. You can often prove statements about congruences by reducing them to statements about divisibility.

2. You can often prove statements about divisibility by reducing them to (ordinary) equations.

(a) Suppose a = b (mod n) and c = d (mod n).


a = b (mod n) means n | a − b and c = d (mod n) means n | c − d. By properties of divisibility,

n | (a − b) + (c − d) = (a + c) − (b + d).

Therefore, a + c = b + d (mod n).

(b) Suppose a = b (mod n) and c = d (mod n).


a = b (mod n) means n | a − b, which means a − b = jn for some j ∈ Z. c = d (mod n) means n | c − d,
which means c − d = kn for some k ∈ Z. Thus, a = b + jn, c = d + kn, and hence

ac = (b + jn)(d + kn) = bd + bkn + djn + jkn2 = bd + n(bk + dj + jkn).

This gives ac − bd = n(bk + dj + jkn), so n | ac − bd, and hence ac = bd (mod n).

(c) Suppose a = b (mod n). This means that n | a − b. By properties of divisibility,

n | (a − b)c = ac − bc.

Therefore, ac = bc (mod n).

Example. (Solving a congruence) Solve 3x + 4 = 2x + 8 (mod 9).

In this case, I’ll solve the modular equation by adding or subtracting the same thing from both sides.

3x + 4 = 2x + 8 (mod 9)
− 4 = 4 (mod 9)
3x = 2x + 4 (mod 9)
− 2x = 2x (mod 9)
x = 4 (mod 9)

The solution is x = 4 (mod 9).

Example. Reduce 497 · 498 · 499 (mod 500) to a number in the range {0, 1, . . . 499}, doing the computation
by hand.

Note that

497 = −3 (mod 500) , 498 = −2 (mod 500) , 499 = −1 (mod 500) .

So
497 · 498 · 499 = (−3)(−2)(−1) = −6 = 494 (mod 500) .

The next result says that congruence mod n is an equivalence relation.

2
Proposition.

(a) (Reflexivity) a = a (mod n) for all a ∈ Z.

(b) (Symmetry) Let a, b ∈ Z. If a = b (mod n), then b = a (mod n).

(c) (Transitivity) Let a, b, c ∈ Z. If a = b (mod n) and b = c (mod n), then a = c (mod n).

Proof. (a) If a ∈ Z, then n | a − a, so a = a (mod n).

(b) If a = b (mod n), then n | a − b, so n | −(a − b) = b − a. Therefore, b = a (mod n).

(c) Suppose a = b (mod n) and b = c (mod n). a = b (mod n) means n | a − b; b = c (mod n) means
n | b − c. Therefore,
n | (a − b) + (b − c) = a − c.

Hence, a = c (mod n).

An equivalence relation on a set gives rise to a partition of the set into equivalence classes. In the case
of congruence mod n, an equivalence class consists of integers congruent to each other mod n.

Definition. Zn (read “Z mod n”) is the set of equivalence classes under congruence mod n.

Example. (Congruence classes mod 3) Find the equivalence classes of the relation congruence mod 3
on the set of integers.

Relative to the equivalence relation of congruence mod 3 on Z, the integers break up into three disjoint
sets:
-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10

-10 -7 -4 -1 2 5 8

-9 -6 -3 0 3 6 9

-8 -5 -2 1 4 7 10

All the elements of a given set are congruent mod 3, and no element in one set is congruent mod 3 to
an element of another. The sets divide up the integers like three puzzle pieces.
It’s cumbersome to write and use equivalence classes as is, since each equivalence class is a set (infinite, in
this case). It’s customary to choose a representative from each equivalence class and use the representatives
to do arithmetic. I’ll choose
0 from {. . . , −9, −6, −3, 0, 3, 6, 9, . . .},

1 from {. . . , −8, −5, −2, 1, 4, 7, 10, . . .},

2 from {. . . , −7, −4, −1, 2, 5, 8, 11, . . .}.

I’ll abuse notation and write


Z3 = {0, 1, 2}.

3
Z3 is called the cyclic group of order 3. The “cyclic” nature of Z3 can be visualized by arranging
the integers in a spiral, with each congruence class on a ray.

8 6
5 3
2 0
-1 -3

-2

When you do arithmetic in Z3 , it is as if you count in a circle: 0, 1, 2, then back to 0 again.


You can form other cyclic groups in an analogous way. For example,

Z6 = {0, 1, 2, 3, 4, 5}.

You can do arithmetic in Zn by adding and multiplying as usual, but reducing the results mod n.

Example. (Operation tables for Z3 ) Construct addition and multiplication tables for Z3 .

+ 0 1 2 · 0 1 2
0 0 1 2 0 0 0 0
1 1 2 0 1 0 1 2
2 2 0 1 2 0 2 1

For example, as integers 2 + 2 = 4. I divide 4 by the modulus 3 and get a remainder of 1. Hence,
2 + 2 = 1.
Likewise, 2 · 2 = 4 = 1 in Z3 .

Example. (Equations in Zn ) Find 6 · 7 in Z11 , 13 + 19 in Z21, and −8 in Z17 .

6 · 7 = 9 in Z11 .
13 + 19 = 11 in Z21 .
−8 = 9 in Z17 .
−8 means the additive inverse of 8. The last statement is just another way of saying −8 = 9 (mod 17).

Example. (Using modular arithmetic in a divisibility proof) Prove that if n is an integer, then
2n2 + 3n + 2 is not divisible by 5.

4
Every integer n is congruent to one of 0, 1, 2, 3, or 4 mod 5. Therefore, I have 5 cases. In each case, I
want to show that 2n2 + 3n + 2 is not divisible by 5 — or to say it in terms of congruences, I want to show
that 2n2 + 3n + 2 6= 0 (mod 5).
I set n = 0, 1, 2, 3, 4 (mod 5) and “substitute” the value into 2n2 + 3n + 2. This substitution is justified
by the properties of congruences I discussed above.
For example, if n = 3 (mod 5), then

n · n = 3 · 3 (mod 5)
n2 = 9 = 4 (mod 5)
2 · n2 = 2 · 4 (mod 5)
2n2 = 8 = 3 (mod 5)

Likewise, 3n = 3 · 3 = 9 = 4 (mod 5). So

2n2 + 3n + 2 = 3 + 4 + 2 = 9 = 4 (mod 5) .

Essentially, I can plug n = 3 into 2n2 + 3n + 2, then reduce the result mod 5 to one of 0, 1, 2, 3, or 4.
Continuing in this way, I get the following table:

n (mod 5) 0 1 2 3 4
2
2n + 3n + 2 (mod 5) 2 2 1 4 1

In all five cases, 2n2 + 3n + 2 6= 0 (mod 5). Therefore, 2n2 + 3n + 2 is never divisible by 5.

I showed earlier how to use algebraic operations to solve simple modular equations. How would you
solve something like this:
6x = 13 (mod 25)?
I’d like to divide both sides by 6, but I only know how to add and multiply. I can subtract, but that’s
because I can add additive inverses. Well, division is multiplication by the multiplicative inverse; what is a
multiplicative inverse mod 25?

Definition. Let a, b ∈ Zn . a and b are multiplicative inverses if ab = 1 (mod n) (or ab = 1 in Zn ).


If a is the multiplicative inverse of b, you can write a = b−1 .
1
(You don’t write “ ” unless you’re in a number system like the rational numbers where fractions are in
b
use.)

Example. (Modular multiplicative inverses) (a) Prove that 6 and 2 are multiplicative inverses mod 11.

(b) Show that 8 does not have a multiplicative inverse mod 12.

(a) 6 · 2 = 1 (mod 11).

(b) One tedious way is to take cases:

n 0 1 2 3 4 5
8n (mod 12) 0 8 4 0 8 4
n 6 7 8 9 10 11
8n (mod 12) 0 8 4 0 8 4

5
No number multiplied by 8 gives 1 mod 12.
I could try all the possibilities because the numbers were small. How would you do this kind of problem
if the numbers were larger?
One approach is to simply appeal to the result following this example. However, I can also give a proof
by contradiction.
Suppose that 8 has a multiplicative inverse mod 12. Let x be the multiplicative inverse. Then 8x =
1 (mod 12). Multiplying both sides by 3, I get

24x = 3 (mod 12) , or 0 = 3 (mod 12) .

This is a contradiction, since 0 and 3 do not differ by a multiple of 12. Therefore, 8 does not have a
multiplicative inverse mod 12.

Proposition. m ∈ Zn has a multiplicative inverse if and only if (m, n) = 1.


Proof. Suppose m ∈ Zn has a multiplicative inverse, so

km = 1 for some k ∈ Zn .

I can regard this as a statement in Z:

km = 1 (mod n) .

This means that km and 1 differ by a multiple of n:

km − 1 = an for some a ∈ Z.

Thus,
km − an = 1.
This is a linear combination of m and n which gives 1. Therefore, (m, n) = 1.
Conversely, suppose (m, n) = 1. I may find integers a and b such that

am + bn = 1.

That is,
am = 1 (mod n) .
Now regarded as an equation in Zn , this says

am = 1 in Zn .

That is, m has multiplicative inverse a.

Example. (Using the Extended Euclidean algorithm to find modular inverses) Find the multi-
plicative inverse of 31 in Z52 .

Note that (31, 52) = 1. Apply the Extended Euclidean Algorithm:

52 - 5
31 1 3
21 1 2
10 2 1
1 10 0

6
Thus,
1 = 3 · 52 + (−5) · 31.
In Z52 , 52 = 0 and −5 = 47. The equation says 1 = 47 · 31. Thus, 47 is the multiplicative inverse of 31
in Z52 .

Theorem. If (a, n) = 1, then the following equation has a unique solution:

ax = b in Zn .

Proof. If (a, n) = 1, then a has a multiplicative inverse a−1 in Zn . Thus, aa−1 = 1 in Zn .


First, this means that x = a−1 b is a solution, since

a(a−1 b) = (aa−1 )b = 1 · b = b.

Second, if x′ is another solution, then ax′ = b. Multiplying both sides by a−1 , I get

a−1 ax′ = a−1 b, x′ = a−1 b.

That is, x′ = x. This means the solution is unique.

Example. (Solving modular equations using modular inverses) Solve

13x = 12 (mod 15) .

There is a solution, since (13, 15) = 1. I need to find a multiplicative inverse for 13 mod 15.

15 - 7
13 1 6
2 6 1
1 2 0

The Extended Euclidean Algorithm says that

(−6)(15) + (7)(13) = 1.

Hence, 7 · 13 = 1 (mod 15), i.e. 7 is the multiplicative inverse of 13 mod 15.


Multiply the original equation by 7:

7 · 13x = 7 · 12 (mod 15) , x = 84 = 9 (mod 15) .

Proposition. Suppose
ac = bc (mod n) .
Then  
n
a=b mod .
(n, c)

7
Proof. I have

ac = bc (mod n)
 
c c n
a =b mod
(n, c) (n, c) (n, c)
c c n
a −b =k· for some k ∈ Z
(n, c) (n, c) (n, c)
c n
(a − b) = k ·
(n, c) (n, c)
c n n
(Note that (n, c) | c and (n, c) | n, so and are actually integers.) Now divides
(n, c) (n, c) (n, c)
c
(a − b), but
(n, c)  
n c
, = 1.
(n, c) (n, c)
n
By Euclid’s lemma, | a − b. Hence,
(n, c)
 
n
a=b mod .
(n, c)

I can use the preceding result to solve some congruences when I can’t immediately use modular inversion.

Example. Solve
12x = 30 (mod 34) .
Since (12, 34) = 2 6= 1, 12 doesn’t have a multiplicative inverse mod 34. I’ll use the preceding result. I
“cancel” a factor of 6 from 12x and 30, and divide the modulus 34 by (6, 34) = 2:

12x = 30 (mod 34)


6 · 2x = 6 · 5 (mod 34)
2x = 5 (mod 17)
9 · 2x = 9 · 5 (mod 17)
x = 45 = 11 (mod 17)

Since the original congruence was mod 34, I must find all numbers in {0, 1, 2, . . . 33} which satisfy
x = 11 (mod 17). One is obviously 11. Adding 17, I find that 11 + 17 = 28 also works. (Adding 17 again
takes me out of the set {0, 1, 2, . . . 33}.)
The solutions are x = 11 (mod 17) and x = 28 (mod 17).


c 2018 by Bruce Ikenaga 8

You might also like