Skip to content

Commit d1d7a59

Browse files
authored
Add CRT two moduli solution
1 parent 921fc8a commit d1d7a59

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/algebra/chinese-remainder-theorem.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ $$\begin{align}
3737

3838
(As above, assume that $m = m_1 m_2 \cdots m_k$ and $m_i$ are pairwise coprime).
3939

40+
## Solution for Two Moduli
41+
42+
Consider a system of two equations for coprime $m_1, m_2$:
43+
44+
$$
45+
\begin{align}
46+
a &\equiv a_1 \pmod{m_1} \\
47+
a &\equiv a_2 \pmod{m_2} \\
48+
\end{align}
49+
$$
50+
51+
We want to find a solution for $a \pmod{m_1 m_2}$. Using the [Extended Euclidean Algorithm](extended-euclid-algorithm.md) we can find Bézout coefficients $n_1, n_2$ such that
52+
53+
$$n_1 m_1 + n_2 m_2 = 1$$
54+
55+
Then a solution will be
56+
57+
$$a = a_1 n_2 m_2 + a_2 n_1 m_1$$
58+
59+
We can easily verify $a = a_1 (1 - n_1 m_1) + a_2 n_1 m_1 \equiv a_1 \pmod{m_1}$ and vice versa.
60+
4061
## Garner's Algorithm
4162

4263
Another consequence of the CRT is that we can represent big numbers using an array of small integers. For example, let $p$ be the product of the first $1000$ primes. From calculations we can see that $p$ has around $3000$ digits.

0 commit comments

Comments
 (0)