Difference between revisions of "Chinese Remainder Theorem"
(→Theorem) |
m (→Solving a system of congruences using CRT) |
||
(12 intermediate revisions by 10 users not shown) | |||
Line 1: | Line 1: | ||
− | The '''Chinese Remainder Theorem''' is a [[number theory | number theoretic]] result | + | The '''Chinese Remainder Theorem''' is a [[number theory | number theoretic]] result. |
== Theorem == | == Theorem == | ||
Line 6: | Line 6: | ||
Let <math>m</math> be [[relatively prime]] to <math>n</math>. Then each [[residue class]] mod <math>mn</math> is equal to the [[intersection]] of a unique residue class mod <math>m</math> and a unique residue class mod <math>n</math>, and the intersection of each residue class mod <math>m</math> with a residue class mod <math>n</math> is a residue class mod <math>mn</math>. | Let <math>m</math> be [[relatively prime]] to <math>n</math>. Then each [[residue class]] mod <math>mn</math> is equal to the [[intersection]] of a unique residue class mod <math>m</math> and a unique residue class mod <math>n</math>, and the intersection of each residue class mod <math>m</math> with a residue class mod <math>n</math> is a residue class mod <math>mn</math>. | ||
+ | This means that if we have <math>b \equiv c \pmod {mn}</math> we can deduce that <math>b \equiv c \pmod{m}</math> and <math>b \equiv c \pmod{n}.</math> | ||
Simply stated: | Simply stated: | ||
Line 22: | Line 23: | ||
Now if the numbers <math>a_{i}</math> satisfy: | Now if the numbers <math>a_{i}</math> satisfy: | ||
<center> | <center> | ||
− | <math>a_{i}b_{i} | + | <math>a_{i}b_{i} \equiv 1 \pmod {d_{i}} </math> |
</center> | </center> | ||
for every <math>1 \leq i \leq n</math>, then a solution for <math>x</math> is: | for every <math>1 \leq i \leq n</math>, then a solution for <math>x</math> is: | ||
Line 35: | Line 36: | ||
== Applicability == | == Applicability == | ||
− | Much like the [[Fundamental Theorem of Arithmetic]], many people seem to take this theorem for granted before they consciously turn their attention to it. | + | Much like the [[Fundamental Theorem of Arithmetic]], many people seem to take this theorem for granted before they consciously turn their attention to it. Its ubiquity derives from the fact that many results can be easily proven mod (a power of a prime), and can then be generalized to mod <math>m</math> using the Chinese Remainder Theorem. For instance, [[Fermat's Little Theorem]] may be generalized to the [[Fermat-Euler Theorem]] in this manner. |
'''General Case''': the proof of the general case follows by induction to the above result (k-1) times. | '''General Case''': the proof of the general case follows by induction to the above result (k-1) times. | ||
+ | |||
+ | ==Solving a system of congruences using CRT== | ||
+ | In order to solve a system of n congruences, it is typical to solve the first two, then combine that with the third, and so on. So, it suffices to know how solve a system of 2 congruences. | ||
+ | |||
+ | Let the system be (where <math>m</math> and <math>n</math> are relatively coprime): | ||
+ | |||
+ | <cmath>x\equiv a \mod m</cmath> | ||
+ | <cmath>x\equiv b \mod n</cmath> | ||
+ | |||
+ | Then if we find one value <math>k</math> such that <math>x=k</math> satisfies the system, then the solution set consists of <math>x\equiv k \mod mn</math>. To find such <math>k</math>, set <math>x=cm+a=dn+b</math>. Then, find <math>c, d</math> that satisfy the equality. This is usually easier than brute forcing for <math>k</math>. | ||
+ | |||
+ | Let's take an example: | ||
+ | <cmath>x\equiv 1 \mod 2</cmath> | ||
+ | <cmath>4x\equiv 3 \mod 5</cmath> | ||
+ | First simplify the second equation to <math>x\equiv 3\cdot 4 \equiv 2 \mod 5</math> using modular inverses. So we have: | ||
+ | <cmath>x\equiv 1 \mod 2</cmath> | ||
+ | <cmath>x\equiv 2 \mod 5</cmath> | ||
+ | Then let <math>x=2a+1=5b+2</math>. A clear solution <math>a,b</math> for this is <math>a=3, b=1</math>. Then, <math>x=7</math> is one solution to the system, so <math>x\equiv 7 \mod 10</math> is the set of all solutions. | ||
+ | |||
+ | If <math>m</math> and <math>n</math> are not relatively prime, then let <math>\gcd(m, n)=g</math>. We split the system as follows: | ||
+ | <cmath>x\equiv a \mod \frac{m}{g}</cmath> | ||
+ | <cmath>x\equiv a \mod g</cmath> | ||
+ | <cmath>x\equiv b \mod g</cmath> | ||
+ | <cmath>x\equiv b \mod \frac{n}{g}</cmath> | ||
+ | Then, we must check that <math>a\equiv b\mod g</math>. If so, simply ignore the 3rd congruence. Now, we have: | ||
+ | <cmath>x\equiv a \mod \frac{m}{g}</cmath> | ||
+ | <cmath>x\equiv a \mod g</cmath> | ||
+ | <cmath>x\equiv b \mod \frac{n}{g}</cmath> | ||
+ | Now we have a system of 3 congruences, which we can solve for. If <math>\gcd(\frac{m}{g}, g)</math> is not <math>1</math>, then repeat the decomposition. Essentially, decompose until we get a system of pairwise relatively prime congruences. Then solve. | ||
==Extended version of the theorem== | ==Extended version of the theorem== |
Latest revision as of 14:57, 6 May 2023
The Chinese Remainder Theorem is a number theoretic result.
Contents
Theorem
Formally stated, the Chinese Remainder Theorem is as follows:
Let be relatively prime to
. Then each residue class mod
is equal to the intersection of a unique residue class mod
and a unique residue class mod
, and the intersection of each residue class mod
with a residue class mod
is a residue class mod
.
This means that if we have we can deduce that
and
Simply stated:
Suppose you wish to find the least number which leaves a remainder of:
such that ,
, ...
are all relatively prime.
Let
, and
.
Now if the numbers
satisfy:
for every , then a solution for
is:
Proof
If , then
and
differ by a multiple of
, so
and
. This is the first part of the theorem. The converse follows because
and
must differ by a multiple of
and
, and
. This is the second part of the theorem.
Applicability
Much like the Fundamental Theorem of Arithmetic, many people seem to take this theorem for granted before they consciously turn their attention to it. Its ubiquity derives from the fact that many results can be easily proven mod (a power of a prime), and can then be generalized to mod using the Chinese Remainder Theorem. For instance, Fermat's Little Theorem may be generalized to the Fermat-Euler Theorem in this manner.
General Case: the proof of the general case follows by induction to the above result (k-1) times.
Solving a system of congruences using CRT
In order to solve a system of n congruences, it is typical to solve the first two, then combine that with the third, and so on. So, it suffices to know how solve a system of 2 congruences.
Let the system be (where and
are relatively coprime):
Then if we find one value such that
satisfies the system, then the solution set consists of
. To find such
, set
. Then, find
that satisfy the equality. This is usually easier than brute forcing for
.
Let's take an example:
First simplify the second equation to
using modular inverses. So we have:
Then let
. A clear solution
for this is
. Then,
is one solution to the system, so
is the set of all solutions.
If and
are not relatively prime, then let
. We split the system as follows:
Then, we must check that
. If so, simply ignore the 3rd congruence. Now, we have:
Now we have a system of 3 congruences, which we can solve for. If
is not
, then repeat the decomposition. Essentially, decompose until we get a system of pairwise relatively prime congruences. Then solve.
Extended version of the theorem
Suppose one tried to divide a group of fish into ,
and
parts instead and found
,
and
fish left over, respectively. Any number with remainder
mod
must be odd and any number with remainder
mod
must be even. Thus, the number of objects must be odd and even simultaneously, which is a contradiction. Thus, there must be restrictions on the numbers
to ensure that at least one solution exists. It follows that:
The solution exists if and only if for all
where
stands for the greatest common divisor. Moreover, in the case when the problem is solvable, any two solutions differ by some common multiple of
. (the extended version).
See Also
Discussion
- Here is an AoPS thread in which the Chinese Remainder Theorem is discussed and implemented.