Chinese Remainder Theorem Calculator
- The Chinese remainder theorem says that remainders modulo coprime numbers pin a number down uniquely modulo their product: solve each congruence separately, then combine.
- Here x leaves remainder 2 on division by 3 and remainder 3 on division by 5. Writing x as 2 plus 3 t and solving for t with the extended Euclidean algorithm gives t of 2.
- That makes the smallest non-negative solution x = 8, and every other solution is 15 away: the next is 23. Check: 8 mod 3 is 2 and mod 5 is 3, as required.
- The theorem is more than a puzzle trick - it is how RSA decryption is sped up in practice, and how calendar and gearing cycles that run on different periods are reconciled to a single repeating schedule.
This Chinese remainder calculator rebuilds a number from its remainders. The Chinese remainder theorem tells us that for coprime moduli there is exactly one solution modulo their product, and the tool applies that rule to the numbers you enter. For example, remainder 2 on division by 3 and remainder 3 on division by 5 give x = 8, repeating every 15, so the next solution is 23. Remainder 1 mod 4 and remainder 3 mod 7 give x = 17, repeating every 28. Remainder 3 mod 7 and remainder 4 mod 9 give x = 31, repeating every 63. You get the smallest solution plus the modulus that the answers repeat by.
The method behind the calculator is the accepted standard for this kind of problem because it is a direct construction from the theorem, not an estimate. It writes x as the first remainder plus the first modulus times t, then solves for t with the extended Euclidean algorithm, with the modular inverse doing the combining. That makes the result exact and repeatable. This page shows the formula, step-by-step workings, worked examples and sources, so you can follow each stage of the calculation and check the answer yourself.
Worked examples
Remainders 2 mod 3, 3 mod 5
The smallest number that is 2 mod 3 and 3 mod 5 is 8. (2 · 3 · 3 · 5)
| Smallest solution x | 8 |
| Combined modulus | 15 |
| Next solution | 23 |
| General solution | x = 8 + 15k for any integer k |
Remainders 1 mod 4, 3 mod 7
The smallest number that is 1 mod 4 and 3 mod 7 is 17. (1 · 4 · 3 · 7)
| Smallest solution x | 17 |
| Combined modulus | 28 |
| Next solution | 45 |
| General solution | x = 17 + 28k for any integer k |
Remainders 3 mod 7, 4 mod 9
The smallest number that is 3 mod 7 and 4 mod 9 is 31. (3 · 7 · 4 · 9)
| Smallest solution x | 31 |
| Combined modulus | 63 |
| Next solution | 94 |
| General solution | x = 31 + 63k for any integer k |
What the Chinese remainder theorem is
The Chinese remainder theorem is a way to rebuild a single number from the remainders it leaves when divided by several other numbers. Stated for the simplest case of two congruences: suppose you want a number x that leaves remainder a when divided by modulus m, and remainder b when divided by modulus n. If m and n are coprime — that is, they share no common factor other than 1 — then there is exactly one solution modulo the product m × n. In other words, the pair of remainders pins down x completely, up to adding or subtracting multiples of m × n. This is the idea a chinese remainder calculator applies to your inputs.
The word "coprime" is doing the real work here. Because m and n share no factor, the product m × n is the smallest number that both moduli divide evenly into, and within each block of that length the two remainder conditions line up exactly once. That is why the answer is unique per cycle: the pattern of remainders repeats every m × n, and each cycle contains precisely one x that satisfies both conditions at the same time.
Concrete examples make the repetition easy to see. Remainder 2 on division by 3 and remainder 3 on division by 5 give x = 8, and the solution repeats every 15 — the next solution is 23. Remainder 1 mod 4 and remainder 3 mod 7 give x = 17, repeating every 28. Remainder 3 mod 7 and remainder 4 mod 9 give x = 31, repeating every 63. In each case the spacing between solutions is exactly the product of the two moduli, just as the theorem promises.
The standard construction builds the answer step by step. Write x as the first remainder plus the first modulus times an unknown t: x = a + m·t. Substituting that into the second congruence turns the problem into a single equation for t, which is solved with the extended Euclidean algorithm. The modular inverse that algorithm produces is what does the combining, merging the two remainder conditions into one number. Once t is known, x follows directly, and reducing it modulo m × n gives the smallest nonnegative solution.
So the theorem is not just an existence claim — it is a recipe. Coprime moduli guarantee exactly one answer per cycle of length m × n, and the extended Euclidean algorithm finds it. If you want to check a pair of remainders by hand or see the repeating cycle laid out, the chinese remainder calculator on this page does the arithmetic for you.
The constructive method
The constructive method turns the Chinese remainder theorem into a step-by-step procedure. Instead of guessing, you build the solution directly from the remainders and moduli. The idea is to write the unknown number x as the first remainder plus the first modulus times an integer t. For example, if a number leaves remainder 2 when divided by 3, then x = 2 + 3t for some integer t. This form automatically satisfies the first congruence, so you only need to choose t so that the second congruence also holds.
To find t, substitute x = r1 + m1 t into the second congruence: r1 + m1 t ≡ r2 (mod m2). Rearranging gives m1 t ≡ r2 − r1 (mod m2). Since the moduli are coprime, m1 has a modular inverse modulo m2, and you can find that inverse with the extended Euclidean algorithm. Multiply both sides by the inverse to isolate t modulo m2. The extended Euclidean algorithm not only confirms that the inverse exists but also computes it efficiently, even when the moduli are large.
Once t is known modulo m2, plug it back into x = r1 + m1 t to get a solution. Because t is determined modulo m2, the resulting x is determined modulo m1 × m2, which is the product of the moduli. This matches the theorem: for coprime moduli there is exactly one solution modulo their product. For instance, remainder 2 on division by 3 and remainder 3 on division by 5 give x = 8, repeating every 15 — the next solution is 23. Similarly, remainder 1 mod 4 and remainder 3 mod 7 give x = 17, repeating every 28, and remainder 3 mod 7 and remainder 4 mod 9 give x = 31, repeating every 63.
Always check the answer against both remainders. Take x = 8 from the first example: 8 divided by 3 leaves remainder 2, and 8 divided by 5 leaves remainder 3. For x = 17: 17 mod 4 is 1, and 17 mod 7 is 3. For x = 31: 31 mod 7 is 3, and 31 mod 9 is 4. These quick checks catch arithmetic slips. A chinese remainder calculator automates this constructive method, but understanding the steps helps you trust the result and spot errors.
Reading the three examples
The three worked examples on this page are worth reading side by side, because they show the same pattern at three different scales. In each case the Chinese remainder theorem rebuilds a number from its remainders: for coprime moduli there is exactly one solution modulo their product. The examples differ only in which moduli are used, and that difference is what sets how far apart the answers fall.
Start with the smallest: remainder 2 on division by 3 and remainder 3 on division by 5 give x = 8, repeating every 15 — the next solution is 23. Check it quickly. Eight divided by 3 leaves 2, and 8 divided by 5 leaves 3, so 8 satisfies both conditions. Because 3 and 5 share no factor, the theorem promises one solution per block of 3 × 5 = 15, and 8 is the one inside the first block. Add 15 and you land on 23, which also leaves 2 and 3; add 15 again and you get 38, and so on without end.
The middle example moves up a step: remainder 1 mod 4 and remainder 3 mod 7 give x = 17, repeating every 28. Here the product of the moduli is 4 × 7 = 28, so the answers sit 28 apart. Seventeen leaves 1 when divided by 4 and 3 when divided by 7, and the next value in line is 45. The largest of the three: remainder 3 mod 7 and remainder 4 mod 9 give x = 31, repeating every 63, since 7 × 9 = 63. Thirty-one leaves 3 on division by 7 and 4 on division by 9, and the next solution is 94.
Read together, the three examples are one statement in three costumes. Each answer is the smallest nonnegative solution, and each cycle length is just the product of that example's two moduli: 15, 28 and 63. That is why a chinese remainder calculator returns a single number plus a step size rather than an endless list — the list would be redundant. The general solution x = x0 + Mk covers every answer, where x0 is the solution found inside the first block and M is the product of the moduli. Set k = 0 and you get the smallest answer; set k = 1 and you get the next one; any whole number k, including zero, produces another valid solution, and nothing outside that family works.
The construction behind each example explains where x0 comes from. It writes x as the first remainder plus the first modulus times t, and solves for t with the extended Euclidean algorithm — the modular inverse does the combining. In the 3-and-5 case, x starts as 2 + 3t, and solving brings t to 2, giving 8. The same machinery produces 17 and 31. Once x0 is fixed, the product M does the rest of the work, which is why the three cycle lengths are simply 15, 28 and 63.
Where CRT earns its keep
The Chinese remainder theorem is not just a textbook exercise. Once you see how it works, you start noticing places where rebuilding a number from its remainders is genuinely useful. A chinese remainder calculator makes those cases quick to check, but the ideas behind them are worth understanding on their own.
Start with puzzles that involve repeating cycles. If a number leaves remainder 2 when divided by 3 and remainder 3 when divided by 5, the theorem tells us there is exactly one solution modulo 15, because 3 and 5 are coprime and their product is 15. That solution is x = 8, and it repeats every 15 — so the next one is 23. Similar setups appear with remainder 1 mod 4 and remainder 3 mod 7, giving x = 17 repeating every 28, or remainder 3 mod 7 and remainder 4 mod 9, giving x = 31 repeating every 63. Calendars, rotating schedules, and gear-tooth problems all reduce to this same pattern: several cycles with different lengths, and one moment when they line up.
Cryptography is another place where CRT earns its keep. In RSA, decryption involves raising a number to a large power modulo a large composite modulus. Because that modulus is the product of two primes, the work can be split into two smaller computations — one modulo each prime — and the results recombined with CRT. The payoff is speed: smaller moduli mean smaller intermediate numbers and faster arithmetic, which is why many RSA implementations use this CRT-based approach.
The same trick applies more broadly to splitting big computations into small-modulus pieces. When a calculation is done modulo a large number that factors into coprime parts, you can run the calculation separately under each smaller modulus and then stitch the answers back together. The construction is straightforward: write x as the first remainder plus the first modulus times t, and solve for t using the extended Euclidean algorithm. The modular inverse does the combining, and the theorem guarantees the result is the unique answer modulo the product of the moduli.
These examples share one theme: coprime moduli let you work piece by piece without losing information. Whether the pieces come from calendar cycles, the two primes inside an RSA key, or a deliberately factored modulus, CRT is the tool that puts them back together.
FAQs
What is the Chinese remainder theorem?
The Chinese remainder theorem says that a system of congruences with coprime moduli has exactly one solution modulo the product of the moduli. In other words, once you find one answer, every other answer differs by a multiple of that product, so the solution repeats in a single predictable pattern.
What number is 2 mod 3, 3 mod 5 and 2 mod 7?
With two congruences - 2 mod 3 and 3 mod 5 - the answer is 8, and every number 15 larger: 23, 38 and so on. Adding the third condition, 2 mod 7, narrows this to a single value modulo 105, which you can find with the calculator.
What if the moduli are not coprime?
A solution may still exist if the remainders agree on shared factors, but it is no longer guaranteed or unique in the same way. When moduli share a common factor, the conditions can conflict or leave more than one answer, so the clean single-solution result of the coprime case does not automatically apply.
How are the modular inverses found?
The modular inverses are found with the extended Euclidean algorithm, solving Mi times inverse = 1 modulo mi. That equation gives the inverse of each reduced modulus, and those inverses are what let the construction combine the individual congruences into one solution.
What is the smallest positive solution?
The construction's reduced answer is the smallest positive solution. In the third example that answer is 31, with the general solution x = 31 + 63k. Every value of k gives another valid solution, and reducing modulo the product of the moduli brings you back to 31.
Where is CRT used today?
RSA implementations use the Chinese remainder theorem to speed up private-key operations, since working with smaller pieces is faster than one large calculation. It also underlies residue number systems, which represent numbers by their remainders and are useful in computing because the pieces can be handled independently.