User Rating 0.0
Total Usage 0 times
Is this tool helpful?

Your feedback helps us improve.

About

The Chinese Remainder Theorem (CRT) guarantees a unique solution modulo M = m1 m2 mk for a system of simultaneous congruences x ai (mod mi), provided all moduli are pairwise coprime. Failing the coprimality condition means no solution may exist, or the solution is not unique. Manual computation breaks down rapidly as the product M grows, requiring modular inverses via the Extended Euclidean Algorithm at each step. An arithmetic error in any single inverse propagates through the entire sum and produces a wrong answer silently.

This calculator uses arbitrary-precision integer arithmetic (BigInt) to handle moduli of any practical size without overflow. It validates pairwise coprimality before attempting construction and reports exactly which pair of moduli share a common factor. The step-by-step output exposes every intermediate value (Mi, yi, partial products) so you can verify or use them in coursework. Note: CRT applies only when all moduli are pairwise coprime. For non-coprime systems, the generalized CRT requires compatibility conditions on remainders that this tool does not cover.

chinese remainder theorem CRT calculator modular arithmetic congruence solver number theory extended euclidean algorithm

Formulas

Given k simultaneous congruences:

x a1 (mod m1), x a2 (mod m2), … x ak (mod mk)

where all mi are pairwise coprime (gcd(mi, mj) = 1 for i j), compute the combined modulus:

M = ki=1 mi

For each i, compute the partial product and its modular inverse:

Mi = Mmi, yi = Mi−1 (mod mi)

The modular inverse yi is found via the Extended Euclidean Algorithm, which solves Mi yi + mi t = 1. The unique solution modulo M is:

x ki=1 ai Mi yi (mod M)

Where ai = remainder for congruence i, mi = modulus for congruence i, M = product of all moduli, Mi = partial product excluding mi, yi = modular inverse of Mi modulo mi, x = unique solution in [0, M 1].

Reference Data

System SizeModuli ExampleProduct MSolution xDomain
23, 515x 2 (mod 3), x 3 (mod 5) → 8Textbook intro
33, 5, 7105x 2, 3, 223Classic puzzle
27, 1177x 3, 617Cryptography basics
34, 9, 25900x 1, 2, 3353Prime power moduli
42, 3, 5, 7210x 1, 2, 3, 453Scheduling / cycles
211, 13143x 7, 9139RSA sub-step
35, 7, 11385x 0, 0, 00Trivial case
2100, 373700x 55, 22355Competition math
52, 3, 5, 7, 112310x 1 for all → 1All-ones identity
38, 27, 12527000x 5, 10, 156265Prime power cubes
217, 19323x 10, 15300Number theory HW
43, 5, 7, 111155x 2, 4, 6, 10494Extended system
21000000007, 9982443531018Requires BigIntCompetitive programming

Frequently Asked Questions

The standard CRT requires gcd(mi, mj) = 1 for every pair. If two moduli share a factor, the system may have no solution or requires the generalized CRT, which adds compatibility conditions: ai aj (mod gcd(mi, mj)). This calculator rejects non-coprime inputs and reports exactly which pair fails.
Yes. All internal arithmetic uses JavaScript BigInt, which supports integers of arbitrary size limited only by available memory. Moduli in the range of 1018 or beyond are handled without overflow. Competitive programming primes like 1000000007 and 998244353 work correctly.
The inverse is computed via the Extended Euclidean Algorithm. Given Mi and mi, it finds yi such that Mi yi 1 (mod mi). The inverse exists if and only if gcd(Mi, mi) = 1, which is guaranteed when the moduli are pairwise coprime. If coprimality is violated, the algorithm correctly detects the failure.
The CRT guarantees a unique solution modulo M = m1 m2 mk. The calculator returns the smallest non-negative representative x [0, M 1]. The general solution is x + n M for any integer n.
The Extended Euclidean Algorithm naturally produces Bézout coefficients that can be negative. For instance, solving 35 y 1 (mod 3) may yield y = −1. The calculator normalizes the final result to [0, M 1] but shows raw intermediates for educational transparency.
There is no hard-coded limit. Practically, the pairwise coprimality check is O(k2) and the product M grows exponentially with k. Systems of 20 - 50 congruences with moderate moduli compute instantly. Extremely large systems with enormous moduli may cause browser memory pressure due to BigInt size.