Search for a tool
Chinese Remainder

Tool to compute congruences with the chinese remainder theorem. The Chinese Remainder Theorem helps to solve congruence equation systems in modular arithmetic.

Results

Chinese Remainder -

Tag(s) : Arithmetics

Share
Share
dCode and more

dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!


Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!


Feedback and suggestions are welcome so that dCode offers the best 'Chinese Remainder' tool for free! Thank you!

Chinese Remainder

Chinese Remainder Calculator


Loading...
(if this message do not disappear, try to refresh this page)


Answers to Questions (FAQ)

What is the Chinese Remainder Theorem? (Definition)

The Chinese remainder theorem is the name given to a system of congruences (multiple simultaneous modular equations). The original problem is to calculate a number of elements which remainders (of their Euclidean division) are known.

Example: If they are arranged by 3 there remains 2. If they are arranged by 5, there remain 3 and if they are arranged by 7, there remain 2. How many objects are there? This exercise implies to calculate $ x $ such that $ x \equiv 2 \mod 3 $ and $ x \equiv 3 \mod 5 $ and $ x \equiv 2 \mod 7 $

Take a list of $ k $ coprimes integers $ n_1, ..., n_k $ and their product $ n = \prod_{i=1}^k n_i $. For all integers $ a_1, ... , a_k $, it exists another integer $ x $ which is unique modulo $ n $, such as:

$$ \begin{array}{c} x \equiv a_1\pmod{n_1} \\ \ldots \\ x \equiv a_k\pmod{n_k} \end{array} $$

How to calculate Chinese remainder?

To find a solution of the congruence system, take the numbers $ \hat{n}_i = \frac n{n_i} = n_1 \ldots n_{i-1}n_{i+1}\ldots n_k $ which are also coprimes. To find the modular inverses, use the Bezout theorem to find integers $ u_i $ and $ v_i $ such as $ u_i n_i + v_i \hat{n}_i = 1 $. Here, $ v_i $ is the modular inverse of $ \hat{n}_i $ modulo $ n_i $.

Take then the numbers $ e_i = v_i \hat{n}_i \equiv 1 \mod{n_i} $. A particular solution of the Chinese remainders theorem is $$ x = \sum_{i=1}^k a_i e_i $$

dCode accepts numbers as pairs (remainder A, modulo B) in equations of the form x = A mod B

Example: $ (2,3),(3,5),(2,7) \iff \left\{ \begin{array}{ll} x = 2 \mod 3 \\ x = 3 \mod 5 \\ x = 2 \mod 7 \end{array} \right. \Rightarrow x = 23 $

When does the Chinese Remainder Theorem have no solution?

The system of equations with remainders $ r_i $ and modulos $ m_i $ has solutions only if the following modular equation is true: $$ r_1 \mod d = r_2 \mod d = \cdots r_n \mod d $$ with $ d $ the GCD of all modulos $ m_i $.

Source code

dCode retains ownership of the "Chinese Remainder" source code. Any algorithm for the "Chinese Remainder" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "Chinese Remainder" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "Chinese Remainder" or any other element are not public (except explicit open source licence like Creative Commons). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.

Cite dCode

The content of the page "Chinese Remainder" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source. Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).
To cite dCode.fr on another website, use the link: https://www.dcode.fr/chinese-remainder
In a scientific article or book, the recommended bibliographic citation is: Chinese Remainder on dCode.fr [online website], retrieved on 2025-04-16, https://www.dcode.fr/chinese-remainder

Need Help ?

Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!

Questions / Comments

Feedback and suggestions are welcome so that dCode offers the best 'Chinese Remainder' tool for free! Thank you!


https://www.dcode.fr/chinese-remainder
© 2025 dCode — The ultimate collection of tools for games, math, and puzzles.
 
Feedback