4.3. Solving Congruences - Discrete Structures For Computing
4.3. Solving Congruences - Discrete Structures For Computing
Contents
4.3.1. Linear Congruences
4.3.2. Systems of Linear Congruences
4.3.3. Exercises
We know from Section 4.1.3 that working modulo a positive integer forms a special
kind of equivalence relation known as a congruence relation. For example,
4 ≡ 16 mod 6 since 6 ∣ 16 − 4.
Now, we look to include variables in equivalence relations and solve for those
variables.
Linear Congruences
Modular Inverses
Computing Modular Inverses
Systems of Linear Congruences
:
s
Chinese Remainder Theorem
Exercises
The solution to such a congruence is all integers x which satisfy the congruence.
2x ≡ 1 mod 5
In a linear congruence, there are infinitely many possible solutions. In the previouse
example we saw that x = 3 and x = 8 were both solutions. In this case, since x = 3
was a solution, then so is every element in the congruence class of 3. Recall that the
congruence class of 3 modulo 5 is defined as:
:
s
–
3 = {x | x ≡ 3 mod 5}.
Modular Inverses
To solve an equation like ax = b over the reals, we would normally divide through by
a, assuming a ≠ 0, to get x = ab . This is equivalent to multiplying both sides by the
multiplicative inverse of a. A multiplicative inverse of a number is another number
such that their product equals 1.
Over the real numbers we have a ⋅ a1 = 1 for any a. Therefore, we can solve ax = b
by multiplying both sides by a1 .
Just as over the rational numbers or real numbers, there are (often, but not always)
multiplicative inverses when working modulo a number. Given a number x and a
modulus m, the modular multiplicative inverse of x is another number a such that
ax ≡ 1 mod m.
:
s
Modular inverse
3a ≡ 1 mod 7
15 ≡ 1 mod 7
→a≡5 mod 7
We can use modular inverses to solve linear congruences. Let a′ be the inverse of a
modulo m. Then, we have the following:
ax ≡ b mod m
x ≡ a′ b mod m
:
s
Modular inverses may not exist
2⋅0≡0 mod 6
2⋅1≡2 mod 6
2⋅2≡4 mod 6
2⋅3≡0 mod 6
2⋅4≡2 mod 6
2⋅5≡4 mod 6
Computing
Print to PDF Modular Inverses
:
s
Finding the modular inverse of a number can be very challenging. It is easy to find by
inspection the inverse of 3 mod 8 (it is 3 itself since 3 ⋅ 3 = 9 ≡ 1 mod 8).
Theorem 4.3.1
If a and m are relatively prime integers with m > 1, then there exists a
unique modular inverse x of a modulo m satisfying 0 < x < m.
Proof:
We have:
1 − sa = tm
m ∣ (1 − sa)
1 ≡ sa mod m
The previous theorem establishes criteria for a modular inverse to exist. The proof of
this theorem suggests how to compute the inverses: we compute a Bézout relation
betwen the modulus and the number to invert.
151 = 3 ⋅ 45 + 16
45 = 2 ⋅ 16 + 13
16 = 1 ⋅ 13 + 3
13 = 4 ⋅ 3 + 1
3=3⋅1+0
1 = 13 − 4 ⋅ 3
1 = 13 − 4(16 − 1 ⋅ 13) = −4 ⋅ 16 + 5 ⋅ 13
1 = −4 ⋅ 16 + 5(45 − 2 ⋅ 16) = 5 ⋅ 45 − 14 ⋅ 16
57x ≡ 13 mod 67
⎧x ≡ 3 mod 7
⎨
⎩
x ≡ 6 mod 13
⎪
Theorem 4.3.2 (Chinese Remainder Theorem)
⎧x ≡ a mod m
⎨
⎩
x ≡ b mod n
Since m and n are co-prime, by the Bézout theorem there exists integers s, t such
that:
sm + tn = 1
x = bsm + atn
= bsm + a − asm
≡a mod m
s
x = bsm + atn
= b − btn + atn
≡b mod n
:
Therefore y ≡ z mod m ⋅ n. ■
0 ≤ x < 15.
⎪
Now consider uniqueness. Let x = y and x = z be two solutions of this system.
Then, y and z must give the same remainder when divided by m or divided by n.
Therefore, m ∣ y − z and n ∣ y − z.
⎧x ≡ 1 mod 3
⎨
⎩
x ≡ 2 mod 5
Since 3 and 5 are co-prime, Chinese Remainder Theorem states there exists
a unique solution modulo 15. Therefore, there is exactly one solution x with
4.3.3. Exercises
Exercise 4.17
1. 8 modulo 17.
2. 9 modulo 23.
3. 11 modulo 71.
Solution
s
⎪
Solve a system of linear congruences
⎧x ≡ 3 mod 7
⎨
⎩
x ≡ 6 mod 13
Lemma 4.3.3
⎪
Let m and n be co-prime integers.
Solve the following linear congruences. Give the unique positive solution
which is less than the modulus.
1. x ≡ 12 mod 7
2. 2x ≡ 12 mod 7
3. 13x ≡ 15 mod 23
1. 5
2. 6
3. 10
Exercise 4.20
⎧3x ≡ 2 mod 11
⎨
⎩
4x ≡ 6 mod 7
:
s
:
Solution to Exercise 4.20
Exercise 4.21
⎨
⎩
⎪
Computing modular inverses gives:
⎧x ≡ 8 mod 11
x ≡ 12 ≡ 5 mod 7
⎧x ≡ 6 mod 13
⎨
⎩
By Alexander Brandt
© Copyright 2022.
s
x ≡ 12 mod 17