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 .

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.

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 .