Free Chinese Remainder Theorem Calculator
Congruence 1: x ≡ a1 (mod n1)
Congruence 2: x ≡ a2 (mod n2)
Enter your congruences to find the solution
Understanding the Chinese Remainder Theorem
The Chinese remainder theorem (CRT) is a fundamental result in number theory that allows you to solve a system of congruences—equations that specify the remainder when an unknown integer is divided by several given moduli. When the moduli are pairwise coprime, the theorem guarantees a unique solution modulo the product of those moduli. This CRT calculator provides a fast, reliable way to solve such systems online, making modular arithmetic accessible whether you are studying number theory, preparing for competitive exams, or working on cryptographic algorithms.
Modular Arithmetic and Congruences
Before diving into the theorem itself, it helps to recall the concept of a remainder. When an integer is divided by a positive integer , the remainder is the integer between and that satisfies:
for some integer . For example, dividing 17 by 5 gives , so the remainder is 2.
The modulo operation builds on this idea. We say that two numbers and are congruent modulo (written ) if they have the same remainder when divided by . Such expressions are called congruences. They behave much like ordinary equations: you can add, subtract, or multiply both sides by any integer (though division requires care). This simple property makes congruences a powerful tool for working with integers.
The Euclidean Algorithm for GCD
The Euclidean algorithm is an efficient method for finding the greatest common divisor (gcd) of two integers. Given two numbers and with , the algorithm proceeds as follows:
- Set , , and let .
- Determine the integer as the largest multiple of that does not exceed (i.e., the floor of ).
- Compute the remainder .
- If , the algorithm stops and . Otherwise, set , , increase by 1, and repeat from step 2.
At each step we have . For example, to find :
| 1 | 1785 | 3 | 546 | 147 |
| 2 | 546 | 3 | 147 | 105 |
| 3 | 147 | 1 | 105 | 42 |
| 4 | 105 | 2 | 42 | 21 |
| 5 | 42 | 2 | 21 | 0 |
Because , .
Bézout’s Identity
Bézout’s identity (or Bézout’s lemma) states that for any non‑zero integers and , there exist integers and such that:
These coefficients can be found by reversing the steps of the Euclidean algorithm. Continuing with and (gcd 21), we back‑substitute through the equations:
Replacing step by step gives:
so one valid pair is and . Notice that the coefficients need not be positive; they are simply integers that satisfy the identity.
The Chinese Remainder Theorem: Statement and Algorithm
The Chinese remainder theorem brings together congruences, the Euclidean algorithm, and Bézout’s identity. Its formal statement is:
Let be pairwise coprime positive integers (i.e., for ). Then for any integers , the system of congruences
has a unique solution modulo .
In plain language: if you know the remainders of an unknown number when divided by several coprime moduli, you can determine that number uniquely (up to adding a multiple of the product of the moduli).
To solve such a system, follow these steps:
- Compute the product .
- For each modulus , let .
- Use Bézout’s identity to find integers and such that . The number is the multiplicative inverse of modulo .
- Define . Notice that and for .
- A particular solution is . The general solution is .
While the algorithm is straightforward, the manual calculation of the inverses can be tedious. This is where an online CRT solver becomes invaluable.
Worked Example with the Calculator
Consider a classic candy‑distribution problem. A mother has a handful of sweets. When she divides them equally among her three children, one sweet remains. If she also gives one to the neighbor girl (four children total), two sweets remain. Inviting the girl’s brother (five children total) leaves three sweets. How many sweets did she buy?
Let be the number of sweets. The conditions translate into the system:
The moduli 3, 4, 5 are pairwise coprime, so the CRT applies. Using the algorithm:
- , ,
- Find inverses via the Euclidean algorithm:
- For (3,20): , inverse of 20 mod 3 is because →
- For (4,15): inverse of 15 mod 4 is →
- For (5,12): inverse of 12 mod 5 is →
- Then
- The simplest non‑negative solution is .
So the mother bought 58 sweets. This result can be obtained instantly using the Chinese remainder theorem calculator—simply enter the three congruences and the tool returns the smallest positive solution.
Why Use This CRT Solver?
- Speed: Avoid manual back‑substitution and inverse calculations.
- Accuracy: Eliminates arithmetic mistakes when handling larger moduli.
- Flexibility: Works for any number of congruences (as long as the moduli are coprime).
- Educational: The step‑by‑step algorithm is clearly explained, making it a valuable learning aid for modular arithmetic, system of congruences, and number theory.
Whether you are a student or a professional working with cryptographic protocols that rely on the CRT, this tool streamlines the solving process and lets you focus on applying the results.
FAQ
1. What conditions must the moduli satisfy for the Chinese remainder theorem to apply?
All moduli in the system must be pairwise coprime (i.e., the greatest common divisor of any two distinct moduli is 1). If any pair shares a common factor greater than 1, the theorem does not guarantee a unique solution, and the calculator will alert you.
2. How do I use this CRT calculator to solve a system of congruences?
First, choose the number of congruences. Then enter each remainder a_i and its corresponding modulus n_i into the provided fields. Once all inputs are filled in, the calculator instantly displays the smallest non‑negative solution modulo the product of the moduli.
3. What does the result 'x ≡ solution (mod N)' mean?
It means that every integer of the form (solution + k·N), where k is any integer, satisfies all the congruences. The calculator normally shows the smallest non‑negative representative (i.e., the integer between 0 and N‑1).
4. Can the calculator handle non‑coprime moduli?
No, the Chinese remainder theorem requires pairwise coprime moduli to guarantee a unique solution. If you enter moduli that are not coprime, the tool will display an error. In that case you may need to check whether the congruences are consistent and possibly reduce the system manually.
5. Is the Chinese remainder theorem used only in mathematics competitions?
Beyond pure mathematics, the CRT has practical applications in cryptography (e.g., RSA decryption), computer science (efficient arithmetic with large numbers), and coding theory. This solver helps users quickly solve the underlying congruences in such contexts.
How to Use
- Select the number of congruences in your system (2 to 6).
- Enter the remainder a and modulus n for each congruence x ≡ a (mod n).
- The calculator will find the unique solution x modulo N using the Chinese Remainder Theorem.