Section 9.2 Solving linear equations modulo \(m\)
When can we solve \(ax = b\mod m\) for \(x\text{?}\) Before we even start, it's good to have a test to see if there is actually a solution:
Theorem 9.2.1.
The equation \(ax = b\mod m\) has a solution if and only if \(\gcd(a,m)\) divides \(b\text{.}\)
Proof.
An integer \(x\) is a solution to \(ax = b\mod m\) if and only if \(ax=b-my\) for some integer \(y\text{.}\) In other words, \(ax = b\mod m\) has a solution if and only if \(b\) can be written as \(ax + my\) for some integers \(x\) and \(y\text{.}\)
If \(b = ax+my\text{,}\) then the Linear Combination Lemma ensures that \(\gcd(a,m)\) divides \(b\text{.}\)
Conversely, assume that \(\gcd(a,m)\) divides \(b\text{,}\) so that \(b = h\gcd(a,m)\) for some integer \(h\text{.}\) Bezout's identity implies that there exist integers \(x'\) and \(y'\) such that \(\gcd(a,m)=ax'+my'\text{.}\) Hence if \(x = hx'\) and \(y=hy'\text{,}\) then
as desired.
Example 9.2.2.
Find \(x\in \{0,1,...,13\}\) so that \(18x = 10\mod 14\text{.}\)
We see that \(\gcd(18,14)=2\) divides \(10\text{,}\) so there is at least one solution. We can use the Euclidean Algorithm to express \(2\) as an integer linear combination: since \(18 - 14 = 4\text{,}\) and \(14 - 3\cdot 4 = 2\) is the gcd, so we can write
Multiplying this by \(5\text{,}\) we obtain
So \(-15\) is a solution, and so is \(3 = -15 \mod 18\text{.}\)
Note that when finding a solution to \(a = bx\mod m\text{,}\) any integer \(x\) is congruent modulo \(m\) to a number in \(\{0,1,...,m-1\}\text{.}\) Thus, whenever we ask for a solution, we prefer to write it as one of these integers.
Exercise 9.2.3.
Find \(x\) so that \(7x = 8\mod 12\text{.}\)
Since \(\gcd(7,12)=1\text{,}\) we can use the Euclidean Algorithm:
We find
so by multiplying by \(8\text{,}\) we get
Thus \(x = -40\) is a solution, and so is \(8 = -40 \mod 12\text{.}\)