The Chinese remainder theorem is about solutions to congruences. To start, suppose we have the following linear congruence:
This is solvable if and only if \(b\) is divisible by \((a,m)\). Euclid’s algorithm can show that this is sufficient. For example suppose we have
Then, this congruence has no solutions since \((6,45) = 3\) and \(3 \not\mid 7\). On the other hand the congruence
has a solution since \((6,45) \mid 3\). How do we find the solution in general? well, \(6x \equiv 3 \pmod{45}\) implies that
We can now use Euclid’s algorithm to see that
So \(8\) is a solution to the original equation but so are \(8+15\) and \(8+30\). This is because the original congruence was module \(45\) and we have \(8+15 = 23 \pmod{45}\) and \(8+30 = 38 \pmod{45}\) but \(8 + 45 = 8 \pmod{45}\). Only when \((a,m) = 1\), the solution is unique and always exists. If \((a,m) > 1\), the solution might not exist or we might have many solutions.
Polynomial Congruences
Suppose we want to solve a polynomial congruence such as
There are a few cases:
- \(m\) is prime. This is easier since since if \((a,m) = 1\), then \(a\) has an inverse module \(m\).
- \(m=p^n\) is a prime power. This can be reduced to the first case (we will see this in a later lecture (Hansel's Lemma)).
- \(m=p_1^{n_1}p_2^{n_2}\cdots\). We will reduce this to the case \(m = p^n\) using the Chinese Remainder Theorem (CRT).
In this lecture, we will study the reduction from case 3 to case 2.
System of Two Linear Congruences
Suppose we want to solve the following system of linear congruences
In general, to have a solution to this system we want \(m_1\) and \(m_2\) to be coprime. This solution is even unique when \(m_1\) and \(m_2\) are coprime. If they were not co-prime, then it’s not guaranteed. We could or could not have a solution.
Example
As an example, suppose we want to solve the following system of linear congruences
Here, we see that \((17,21) = 1\). So then we have
which simplifes to
By Euclid’s algorithm, \(-21z + 17y = 1\) has the solution \(z = 4\) and \(y = 5\). So now we can just double it to get
Chinese Remainder Theorem
Suppose now that we have more than two linear congruences. Then by CRT:
Proof
So let’s focus on the first two equations and instead of using Euclid’s algorithm, let’s define a map from the set of all numbers from \(0\) up to \(m_1m_2 - 1\) to the product set of the numbers from \(0\) to \(m_1\) and \(0\) to \(m_2\).
Given by
We claim that this is is a bijection. First we will show that \(f\) is injective. So suppose that \(f(x) = f(y)\), then we want to show that \(x = y\). Since \(f(x) = f(y)\), then
Therefore
The first equation implies \(x - y\) is divisible by \(m_1\). The second equation implies that \(x-y\) is by \(m_2\). But \(m_1\) and \(m_2\) are coprime so \(x-y\) must also be divisible by the product \(m_1m_2\). This means that
This implies that \(f\) is injective. Now, since we have an injective map between two sets of equal size, then this map must be surjective as well. Therefore, \(f\) is a bijection.
So now since this map is a bijection, then given a pair \((a_1, a_2) \in \mathbb{Z}/m_1, \mathbb{Z}/m_2\), this pair must correspond to exactly one \(x\) in \(\mathbb{Z}/(m_1m_2)\) such that
which is what we wanted to show. Note that this argument actually fails when \(m_1\) and \(m_2\) are not coprime. The map will not be injective.
Example
Suppose we want to solve the following
What does this equation mean? We want to find a number such that they have the same last digit if you square it. For example, \(6^2 = 36\) and
Similarly,
Observe now that
\(5^n\) and \(2^n\) are coprime. Therefore, By CRT if we solve
Then, we are guaranteed that there there exists a unique solution module \(10^n\)
Which is what we want. To solve the first congruence, observe that
There are at least two solutions
Similarly, for \(x^5 \equiv x \pmod{2^n}\), we also get the same two solutions.
So now by CRT, for each pair of solutions, we are guaranteed a solution modulo \(10^n\). For example, consider the pair
By CRT,
However, this isn’t an interesting solution. Let’s try another pair. Consider
Using the first congruence, this implies that \(x = 2^n \cdot t\). Plugging this in into the second congruence, we get
Suppose \(n = 1\), then
The smallest \(t\) satisfying this is \(t = 3\). We can plug this back into
Notice that \(6 \equiv 0 \pmod{2^1}\) and \(6 \equiv 1 \pmod{5^1}\) satisfying both congruences and satisfying
Now, let’s consider trying \(n = 2\) for the same same pair of solutions. Recall that \(x = 2^n \cdot t = 4t\) (using the first congruence). If we plug this into the second congruence, then we get
The smallest \(t\) satisfying this is \(t = 19\). Thus
Therefore, we get the solution
Verifying manually, \(76^2 = 5776\) and \(5776 \pmod{100} = 76\) as we expect!