
In
mathematics, the Chinese remainder theorem states that if one knows the remainders of the
Euclidean division
In arithmetic, Euclidean division – or division with remainder – is the process of dividing one integer (the dividend) by another (the divisor), in a way that produces an integer quotient and a natural number remainder strictly smaller than ...
of an
integer
An integer is the number zero (), a positive natural number (, , , etc.) or a negative integer with a minus sign ( −1, −2, −3, etc.). The negative numbers are the additive inverses of the corresponding positive numbers. In the language ...
''n'' by several integers, then one can determine uniquely the remainder of the division of ''n'' by the product of these integers, under the condition that the
divisor
In mathematics, a divisor of an integer n, also called a factor of n, is an integer m that may be multiplied by some integer to produce n. In this case, one also says that n is a multiple of m. An integer n is divisible or evenly divisible by ...
s are
pairwise coprime
In mathematics, two integers and are coprime, relatively prime or mutually prime if the only positive integer that is a divisor of both of them is 1. Consequently, any prime number that divides does not divide , and vice versa. This is equival ...
(no two divisors share a common factor other than 1).
For example, if we know that the remainder of ''n'' divided by 3 is 2, the remainder of ''n'' divided by 5 is 3, and the remainder of ''n'' divided by 7 is 2, then without knowing the value of ''n'', we can determine that the remainder of ''n'' divided by 105 (the product of 3, 5, and 7) is 23. Importantly, this tells us that if ''n'' is a
natural number
In mathematics, the natural numbers are those numbers used for counting (as in "there are ''six'' coins on the table") and ordering (as in "this is the ''third'' largest city in the country").
Numbers used for counting are called '' cardinal ...
less than 105, then 23 is the only possible value of ''n''.
The earliest known statement of the
theorem
In mathematics, a theorem is a statement that has been proved, or can be proved. The ''proof'' of a theorem is a logical argument that uses the inference rules of a deductive system to establish that the theorem is a logical consequence of ...
is by the Chinese mathematician Sun-tzu in the ''
Sun-tzu Suan-ching'' in the 3rd century CE.
The Chinese remainder theorem is widely used for computing with large integers, as it allows replacing a computation for which one knows a bound on the size of the result by several similar computations on small integers.
The Chinese remainder theorem (expressed in terms of
congruences) is true over every
principal ideal domain
In mathematics, a principal ideal domain, or PID, is an integral domain in which every ideal is principal, i.e., can be generated by a single element. More generally, a principal ideal ring is a nonzero commutative ring whose ideals are princip ...
. It has been generalized to any
ring
Ring may refer to:
* Ring (jewellery), a round band, usually made of metal, worn as ornamental jewelry
* To make a sound with a bell, and the sound made by a bell
:(hence) to initiate a telephone connection
Arts, entertainment and media Film and ...
, with a formulation involving
two-sided ideal
In ring theory, a branch of abstract algebra, an ideal of a ring is a special subset of its elements. Ideals generalize certain subsets of the integers, such as the even numbers or the multiples of 3. Addition and subtraction of even numbers p ...
s.
History
The earliest known statement of the theorem, as a problem with specific numbers, appears in the 3rd-century book ''
Sun-tzu Suan-ching'' by the Chinese mathematician Sun-tzu:
Sun-tzu's work contains neither a
proof
Proof most often refers to:
* Proof (truth), argument or sufficient evidence for the truth of a proposition
* Alcohol proof, a measure of an alcoholic drink's strength
Proof may also refer to:
Mathematics and formal logic
* Formal proof, a con ...
nor a full algorithm. What amounts to an algorithm for solving this problem was described by
Aryabhata
Aryabhata ( ISO: ) or Aryabhata I (476–550 CE) was an Indian mathematician and astronomer of the classical age of Indian mathematics and Indian astronomy. He flourished in the Gupta Era and produced works such as the '' Aryabhatiya'' (whi ...
(6th century). Special cases of the Chinese remainder theorem were also known to
Brahmagupta
Brahmagupta ( – ) was an Indian mathematician and astronomer. He is the author of two early works on mathematics and astronomy: the '' Brāhmasphuṭasiddhānta'' (BSS, "correctly established doctrine of Brahma", dated 628), a theoretical tr ...
(7th century), and appear in
Fibonacci
Fibonacci (; also , ; – ), also known as Leonardo Bonacci, Leonardo of Pisa, or Leonardo Bigollo Pisano ('Leonardo the Traveller from Pisa'), was an Italian mathematician from the Republic of Pisa, considered to be "the most talented Western ...
's
Liber Abaci
''Liber Abaci'' (also spelled as ''Liber Abbaci''; "The Book of Calculation") is a historic 1202 Latin manuscript on arithmetic by Leonardo of Pisa, posthumously known as Fibonacci.
''Liber Abaci'' was among the first Western books to describe ...
(1202). The result was later generalized with a complete solution called ''Da-yan-shu'' () in
Ch'in Chiu-shao's 1247 ''
Mathematical Treatise in Nine Sections
The ''Mathematical Treatise in Nine Sections'' () is a mathematical text written by Chinese Southern Song dynasty mathematician Qin Jiushao in the year 1247. The mathematical text has a wide range of topics and is taken from all aspects of th ...
'' (, ''Shu-shu Chiu-chang'') which was translated into English in early 19th century by British missionary
Alexander Wylie.

The notion of congruences was first introduced and used by
Carl Friedrich Gauss
Johann Carl Friedrich Gauss (; german: Gauß ; la, Carolus Fridericus Gauss; 30 April 177723 February 1855) was a German mathematician and physicist who made significant contributions to many fields in mathematics and science. Sometimes refe ...
in his ''
Disquisitiones Arithmeticae
The (Latin for "Arithmetical Investigations") is a textbook of number theory written in Latin by Carl Friedrich Gauss in 1798 when Gauss was 21 and first published in 1801 when he was 24. It is notable for having had a revolutionary impact on th ...
'' of 1801. Gauss illustrates the Chinese remainder theorem on a problem involving calendars, namely, "to find the years that have a certain period number with respect to the solar and lunar cycle and the Roman indiction." Gauss introduces a procedure for solving the problem that had already been used by
Leonhard Euler
Leonhard Euler ( , ; 15 April 170718 September 1783) was a Swiss mathematician, physicist, astronomer, geographer, logician and engineer who founded the studies of graph theory and topology and made pioneering and influential discoveries in ma ...
but was in fact an ancient method that had appeared several times.
Statement
Let ''n''
1, ..., ''n''
''k'' be integers greater than 1, which are often called ''
moduli'' or ''
divisors
In mathematics, a divisor of an integer n, also called a factor of n, is an integer m that may be multiplied by some integer to produce n. In this case, one also says that n is a multiple of m. An integer n is divisible or evenly divisible by ...
''. Let us denote by ''N'' the product of the ''n''
''i''.
The Chinese remainder theorem asserts that if the ''n''
''i'' are
pairwise coprime
In mathematics, two integers and are coprime, relatively prime or mutually prime if the only positive integer that is a divisor of both of them is 1. Consequently, any prime number that divides does not divide , and vice versa. This is equival ...
, and if ''a''
1, ..., ''a''
''k'' are integers such that 0 ≤ ''a''
''i'' < ''n''
''i'' for every ''i'', then there is one and only one integer ''x'', such that 0 ≤ ''x'' < ''N'' and the remainder of the
Euclidean division
In arithmetic, Euclidean division – or division with remainder – is the process of dividing one integer (the dividend) by another (the divisor), in a way that produces an integer quotient and a natural number remainder strictly smaller than ...
of ''x'' by ''n''
''i'' is ''a''
''i'' for every ''i''.
This may be restated as follows in terms of
congruences
In abstract algebra, a congruence relation (or simply congruence) is an equivalence relation on an algebraic structure (such as a group, ring, or vector space) that is compatible with the structure in the sense that algebraic operations done wit ...
:
If the
are pairwise coprime, and if ''a''
1, ..., ''a''
''k'' are any integers, then the system
:
has a solution, and any two solutions, say ''x''
1 and ''x''
2, are congruent modulo ''N'', that is, .
In
abstract algebra
In mathematics, more specifically algebra, abstract algebra or modern algebra is the study of algebraic structures. Algebraic structures include groups, rings, fields, modules, vector spaces, lattices, and algebras over a field. The te ...
, the theorem is often restated as: if the ''n''
''i'' are pairwise coprime, the map
:
defines a
ring isomorphism
In ring theory, a branch of abstract algebra, a ring homomorphism is a structure-preserving function between two rings. More explicitly, if ''R'' and ''S'' are rings, then a ring homomorphism is a function such that ''f'' is:
:addition preser ...
:
between the
ring
Ring may refer to:
* Ring (jewellery), a round band, usually made of metal, worn as ornamental jewelry
* To make a sound with a bell, and the sound made by a bell
:(hence) to initiate a telephone connection
Arts, entertainment and media Film and ...
of
integers modulo ''N'' and the
direct product
In mathematics, one can often define a direct product of objects already known, giving a new one. This generalizes the Cartesian product of the underlying sets, together with a suitably defined structure on the product set. More abstractly, one t ...
of the rings of integers modulo the ''n''
''i''. This means that for doing a sequence of arithmetic operations in
one may do the same computation independently in each
and then get the result by applying the isomorphism (from the right to the left). This may be much faster than the direct computation if ''N'' and the number of operations are large. This is widely used, under the name ''multi-modular computation'', for
linear algebra
Linear algebra is the branch of mathematics concerning linear equations such as:
:a_1x_1+\cdots +a_nx_n=b,
linear maps such as:
:(x_1, \ldots, x_n) \mapsto a_1x_1+\cdots +a_nx_n,
and their representations in vector spaces and through matric ...
over the integers or the
rational number
In mathematics, a rational number is a number that can be expressed as the quotient or fraction of two integers, a numerator and a non-zero denominator . For example, is a rational number, as is every integer (e.g. ). The set of all ra ...
s.
The theorem can also be restated in the language of
combinatorics
Combinatorics is an area of mathematics primarily concerned with counting, both as a means and an end in obtaining results, and certain properties of finite structures. It is closely related to many other areas of mathematics and has many a ...
as the fact that the infinite
arithmetic progression
An arithmetic progression or arithmetic sequence () is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, the sequence 5, 7, 9, 11, 13, 15, . . . is an arithmetic progression with a common differ ...
s of integers form a
Helly family
In combinatorics, a Helly family of order is a family of sets in which every minimal ''subfamily with an empty intersection'' has or fewer sets in it. Equivalently, every finite subfamily such that every -fold intersection is non-empty has non ...
.
Proof
The existence and the uniqueness of the solution may be proven independently. However, the first proof of existence, given below, uses this uniqueness.
Uniqueness
Suppose that and are both solutions to all the congruences. As and give the same remainder, when divided by , their difference is a multiple of each . As the are pairwise coprime, their product also divides , and thus and are congruent modulo . If and are supposed to be non-negative and less than (as in the first statement of the theorem), then their difference may be a multiple of only if .
Existence (first proof)
The map
:
maps
congruence classes modulo to sequences of congruence classes modulo . The proof of uniqueness shows that this map is
injective
In mathematics, an injective function (also known as injection, or one-to-one function) is a function that maps distinct elements of its domain to distinct elements; that is, implies . (Equivalently, implies in the equivalent contraposi ...
. As the
domain
Domain may refer to:
Mathematics
*Domain of a function, the set of input values for which the (total) function is defined
** Domain of definition of a partial function
**Natural domain of a partial function
**Domain of holomorphy of a function
*Do ...
and the
codomain
In mathematics, the codomain or set of destination of a function is the set into which all of the output of the function is constrained to fall. It is the set in the notation . The term range is sometimes ambiguously used to refer to either ...
of this map have the same number of elements, the map is also
surjective
In mathematics, a surjective function (also known as surjection, or onto function) is a function that every element can be mapped from element so that . In other words, every element of the function's codomain is the image of one element of ...
, which proves the existence of the solution.
This proof is very simple but does not provide any direct way for computing a solution. Moreover, it cannot be generalized to other situations where the following proof can.
Existence (constructive proof)
Existence may be established by an explicit construction of . This construction may be split into two steps, first solving the problem in the case of two moduli, and then extending this solution to the general case by
induction on the number of moduli.
Case of two moduli
We want to solve the system:
:
where
and
are
coprime
In mathematics, two integers and are coprime, relatively prime or mutually prime if the only positive integer that is a divisor of both of them is 1. Consequently, any prime number that divides does not divide , and vice versa. This is equival ...
.
Bézout's identity
In mathematics, Bézout's identity (also called Bézout's lemma), named after Étienne Bézout, is the following theorem:
Here the greatest common divisor of and is taken to be . The integers and are called Bézout coefficients for ; they ...
asserts the existence of two integers
and
such that
:
The integers
and
may be computed by the
extended Euclidean algorithm
In arithmetic and computer programming, the extended Euclidean algorithm is an extension to the Euclidean algorithm, and computes, in addition to the greatest common divisor (gcd) of integers ''a'' and ''b'', also the coefficients of Bézout's ...
.
A solution is given by
:
Indeed,
:
implying that
The second congruence is proved similarly, by exchanging the subscripts 1 and 2.
General case
Consider a sequence of congruence equations:
:
where the
are pairwise coprime. The two first equations have a solution
provided by the method of the previous section. The set of the solutions of these two first equations is the set of all solutions of the equation
:
As the other
are coprime with
this reduces solving the initial problem of equations to a similar problem with
equations. Iterating the process, one gets eventually the solutions of the initial problem.
Existence (direct construction)
For constructing a solution, it is not necessary to make an induction on the number of moduli. However, such a direct construction involves more computation with large numbers, which makes it less efficient and less used. Nevertheless,
Lagrange interpolation
In numerical analysis, the Lagrange interpolating polynomial is the unique polynomial of lowest degree that interpolates a given set of data.
Given a data set of coordinate pairs (x_j, y_j) with 0 \leq j \leq k, the x_j are called ''nodes'' an ...
is a special case of this construction, applied to
polynomial
In mathematics, a polynomial is an expression consisting of indeterminates (also called variables) and coefficients, that involves only the operations of addition, subtraction, multiplication, and positive-integer powers of variables. An ex ...
s instead of integers.
Let
be the product of all moduli but one. As the
are pairwise coprime,
and
are coprime. Thus
Bézout's identity
In mathematics, Bézout's identity (also called Bézout's lemma), named after Étienne Bézout, is the following theorem:
Here the greatest common divisor of and is taken to be . The integers and are called Bézout coefficients for ; they ...
applies, and there exist integers
and
such that
:
A solution of the system of congruences is
:
In fact, as
is a multiple of
for
we have
:
for every
Computation
Consider a system of congruences:
:
where the
are
pairwise coprime
In mathematics, two integers and are coprime, relatively prime or mutually prime if the only positive integer that is a divisor of both of them is 1. Consequently, any prime number that divides does not divide , and vice versa. This is equival ...
, and let
In this section several methods are described for computing the unique solution for
, such that