Chinese Remainder Theorem
Given pair-wise coprime moduli and their product , the Chinese Remainder Theorem states that there exists a unique integer that simultaneously satisfies for all .
Moreover, writing and letting denote the modular inverse of , the unique solution for can be explicitly constructed as
where are the basis residues, such that and for all .
Intuition
Although difficult in theory, the CRT is based on the following claim:
- For with that there is exactly one that satisfies the equations and .
The proof for this claim is as follows. Let and . Then, and , whereas and . This means that , and similarly , meaning we have an satisfying the equation.
Examples
How Many Solutions?
Consider the equation for distinct primes . In the below three parts, all values are defined as values in in the range .
If , show that there exists a solution if and only if . We proceed in the following way:
- Sufficiency (): Since , this means that is also a multiple of . As such, we can express , which reduces to . This congruence has a solution as long as (i.e., is invertible). We know that this requirement is satisfied since , meaning that , but .
- Necessity (): Let . Since , then .
If , and there is a solution , show that there are exactly solutions. a
For how many pairs are there exactly solutions?
Since , as shown in the last step. We know that all solutions are of the form . Therefore, it must be that . Since , then is invertible, and we get . We lift to modulo , where we get In the set there are exactly multiples of (including ) that satisfy this condition given the right values of .
Celebrate and Remember Textiles
You’ve decided to knit a 70-themed baby blanket as a gift for your cousin and want to incorporate rows from three different stitch patterns with the following requirements on the row lengths of each of the stitch patterns:
- Alternating Link: Multiple of 8, plus 3
- Double Helix: Multiple of 3, plus 1
- Crossover: Multiple of 7, plus 6
You want to be able to switch between knitting these different patterns without changing the number of stitches on the needle, so you must use a number of stitches that simultaneously meets the requirements of all three patterns.
Find the smallest number of stitches you need to cast on in order to incorporate all three patterns in your baby blanket.
We must solve using CRT for the following system of equations:
x \equiv 3 \pmod{8}, \
x \equiv 1 \pmod{3}, \
x \equiv 6 \pmod{7}.
\end{cases}$$
We construct , and therefore , , . A quick application of EGCD finds that the inverses are , , and . Therefore, which simplifies to .