Chinese Remainder Theorem Calculator
The ultimate online Chinese Remainder Theorem solver. Instantly find solutions to systems of congruences with detailed, step-by-step explanations.
🧮 Chinese Remainder Theorem Calculator
Enter one congruence per line in the format x = a mod m
or a, m
.
Example:
x = 2 mod 3
x = 3 mod 5
x = 2 mod 7
🤔 What is the Chinese Remainder Theorem (CRT)?
The Chinese Remainder Theorem (CRT) is a powerful result from number theory that provides a unique solution to a system of simultaneous linear congruences with coprime moduli. In simpler terms, if you know the remainders of an unknown integer when divided by several different numbers (which are pairwise coprime), the CRT allows you to find that unique integer within a certain range.
This theorem has a rich history, dating back to the 3rd-century Chinese mathematical text "Sunzi Suanjing" (The Mathematical Classic of Sun Zi). The original problem posed was: "There are certain things whose number is unknown. If we count them by threes, we have two left over; by fives, we have three left over; and by sevens, we have two left over. How many things are there?" Our online chinese remainder theorem calculator is designed to solve exactly this type of problem in an instant.
📜 The Core Principle and Formula
Let's say we have a system of congruences:
x ≡ a₂ (mod m₂)
...
x ≡ aₙ (mod mₙ)
Where the moduli m₁, m₂, ..., mₙ are pairwise coprime (i.e., the greatest common divisor of any two is 1, gcd(mᵢ, mⱼ) = 1 for i ≠ j). The Chinese Remainder Theorem guarantees that there is a unique solution for x modulo M, where M = m₁ * m₂ * ... * mₙ.
The solution is found using the following formula:
x = (∑ aᵢ * Mᵢ * yᵢ) mod M
- aᵢ is the remainder for the i-th congruence.
- M is the product of all moduli: M = ∏ mᵢ.
- Mᵢ is the product of all moduli except mᵢ: Mᵢ = M / mᵢ.
- yᵢ is the modular multiplicative inverse of Mᵢ modulo mᵢ. This means Mᵢ * yᵢ ≡ 1 (mod mᵢ). Our chinese remainder theorem calculator with steps will show you exactly how this inverse is found using the Extended Euclidean Algorithm.
⚙️ How the Chinese Remainder Theorem Calculator Works (Step-by-Step)
Our chinese remainder theorem calculator with solution doesn't just give you an answer; it provides a detailed, step-by-step breakdown of the entire process. This makes it a fantastic learning tool. Here’s a walkthrough of the steps the calculator performs:
Step 1: Input Validation
The first and most crucial step is to validate the input. The calculator checks:
- That all remainders and moduli are valid integers.
- That all moduli are greater than 1.
- Coprimality Check: It verifies that all moduli (m₁, m₂, ..., mₙ) are pairwise coprime. It calculates the greatest common divisor (GCD) for every pair of moduli. If any gcd(mᵢ, mⱼ) is not 1, the standard CRT cannot be applied, and the calculator will notify you.
Step 2: Calculate the Product Modulus (M)
The calculator computes the overall modulus M by multiplying all the individual moduli together. This value, M, defines the range within which the unique solution exists.
M = m₁ * m₂ * ... * mₙ
Step 3: Calculate Mᵢ for Each Congruence
For each congruence in the system, it calculates Mᵢ. This is done by dividing the total product M by the modulus of that specific congruence, mᵢ.
Mᵢ = M / mᵢ
This is a key part of the CRT process, and our online chinese remainder theorem calculator handles it flawlessly, even with very large numbers, thanks to its use of BigInt arithmetic.
Step 4: Find the Modular Inverse (yᵢ)
This is often the most complex part of a manual calculation. For each Mᵢ, the calculator needs to find its modular multiplicative inverse, yᵢ, with respect to the original modulus mᵢ. This is the value `yᵢ` that satisfies the equation:
Mᵢ * yᵢ ≡ 1 (mod mᵢ)
Our chinese remainder theorem solver uses the powerful Extended Euclidean Algorithm to find this inverse efficiently and accurately. The step-by-step solution will show you the result of this calculation for each congruence.
Step 5: Sum the Products and Find the Final Solution
Finally, the calculator puts all the pieces together. It computes the sum of the products of `aᵢ * Mᵢ * yᵢ` for all congruences.
Sum = a₁*M₁*y₁ + a₂*M₂*y₂ + ... + aₙ*Mₙ*yₙ
The final unique solution, x, is the remainder of this sum when divided by the total modulus M.
x = Sum mod M
The chinese remainder theorem calculator with work displays this final result clearly, often in the format `x ≡ [solution] (mod M)`.
🐍 Chinese Remainder Theorem Python Implementation
For programmers and data scientists, understanding the algorithmic implementation is key. Our tool can generate a functional Python script to solve the provided system, demonstrating the logic in a practical way. This feature makes it more than just a calculator; it's a coding aid.
The generated Python code typically includes:
- A function to compute the modular inverse using the Extended Euclidean Algorithm, often using Python's `pow(a, -1, m)` for modern versions.
- A main CRT function that takes lists of remainders and moduli as input.
- Clear comments explaining each part of the process, mirroring the steps described above.
This is an invaluable resource for anyone looking to implement a chinese remainder theorem solver in their own projects, whether for competitive programming, academic research, or software development.
💡 Applications of the Chinese Remainder Theorem
The CRT is not just an abstract mathematical curiosity. It has profound applications in various fields:
- Cryptography: The RSA algorithm, a cornerstone of modern internet security, uses the CRT to speed up decryption and signing operations significantly. By breaking down computations over a large modulus into smaller computations over coprime factors, performance is greatly enhanced.
- Computer Science: It's used in algorithms for handling large integers. A very large number can be represented by its remainders modulo a set of smaller, coprime numbers. Arithmetic operations (addition, subtraction, multiplication) can then be performed on these smaller remainders independently and in parallel.
- Coding Theory: It plays a role in error detection and correction codes, such as Goppa codes.
- Astronomy and Calendar Calculations: Historically, it was used to determine the dates of celestial events and create complex calendar cycles that needed to satisfy multiple periodic conditions simultaneously.
- Signal Processing: In Fast Fourier Transform (FFT) algorithms, CRT can be used for frequency analysis.
Using a chinese remainder theorem calculator online like this one can help students and professionals quickly solve problems and check their work in these applied contexts.
🆚 Comparison: Our Tool vs. Wolfram Alpha / Symbolab
While powerful platforms like Wolfram Alpha and Symbolab can solve CRT problems, our dedicated chinese remainder theorem calculator offers distinct advantages:
- Focused Interface: Our tool is built for one purpose, making it incredibly fast and easy to use without the clutter of a general-purpose computational engine.
- Clarity of Steps: The chinese remainder theorem calculator with steps provides a breakdown that is specifically tailored for CRT, making the logic exceptionally clear and easy to follow for educational purposes. A general solver might obscure these specific steps.
- Python Code Generation: The ability to instantly generate a chinese remainder theorem python script is a unique feature that bridges the gap between theory and practical implementation.
- No-Cost, No-Limits: Our tool is completely free, with no hidden paywalls for step-by-step solutions, unlike some features on other platforms.
- Lightweight & Fast: Operating entirely in your browser with Vanilla JavaScript, our calculator is lightning-fast with no server-side processing delays.
In essence, whether you need a quick answer or a deep, educational dive into the process, this online chinese remainder theorem calculator is optimized for the best possible experience.
🎁 Bonus Utility Tools
📊 Column Space Calculator
Find the basis for the column space of any matrix instantly. A key tool for linear algebra.
Open Tool🔄 Matrix Transpose Calculator
Quickly find the transpose Aᵀ of any matrix with our easy-to-use online tool.
Open Tool🌳 Kruskal's Algorithm Calculator
Find the Minimum Spanning Tree (MST) of a graph step-by-step using Kruskal's algorithm.
Open Tool♾️ Limit Definition Calculator
Solve limits using the formal epsilon-delta definition. An advanced tool for calculus students.
Open Tool🧮 Greatest Common Divisor Calculator
Solve for the GCD of two or more numbers with our efficient Euclidean algorithm tool.
Open Tool📈 Differential Equation Calculator
Solve first-order, second-order, and other differential equations with step-by-step solutions.
Open Tool📚 Power Set Calculator
Find all possible subsets (2ⁿ) of a given set. Essential for discrete mathematics.
Open Tool✔️ Validator Tools Hub
A collection of tools to validate code, YAML, APIs, and more to ensure compliance.
Open Tool❤️ Support Our Work
This tool is offered for free. If you find it useful, please consider supporting its development and maintenance through a small donation. Your contribution helps us keep the site running and create more high-quality tools for everyone.
Donate via UPI (India)
Scan the QR code below for a quick and easy UPI payment.

Support via PayPal (International)
Use the link below to contribute securely via PayPal.
