Free Chinese Remainder Theorem calculator: enter x mod m1 and x mod m2 to get the smallest solution, the full solution family and a check of both congruences.

Chinese Remainder Theorem Calculator

Solve simultaneous congruences properly — smallest solution, repeating family, and an honest no-solution answer when there is none.

Free to use Full solution family No-solution detection Save PDF · PNG · Share

Enter your values

Fill in the fields below — the result appears with every step shown.

Shown on the printed, PDF and PNG copies of your result. Leave blank to stay anonymous.

Enter a valid value for remainder 1 (x mod m1).

x leaves this remainder on division by m1.

Enter a valid value for modulus 1 (m1).

First modulus, 2 or more.

Enter a valid value for remainder 2 (x mod m2).

x leaves this remainder on division by m2.

Enter a valid value for modulus 2 (m2).

Second modulus, 2 or more.

Local browser calculation

Review your inputs and the tool’s supported scope before using the result.

Calculator loading… If this message stays, this view is not running the calculator's script — open this file in a full browser tab, then press Calculate.

Your result will appear here

Enter your values above, then press Calculate — or press Enter in any field.
TinyExe Chinese Remainder Theorem Calculator tinyexe.comFree online calculators

TinyExe · Chinese Remainder Theorem Result

Calculated locally in your browser

Calculated on
—

–
—

Name

—

Remainder 1 (x mod m1)

—

Modulus 1 (m1)

—

Remainder 2 (x mod m2)

—

How this was calculated

    What to do next

      TinyExe · tinyexe.com — Runs 100% in your browser — your numbers never leave this tab; nothing is uploaded or stored.

      TinyExe PDF & PNG exports carry the TinyExe logo and tinyexe.com header & footer.

      Runs 100% in your browser — your numbers never leave this tab; nothing is uploaded or stored.

      Embed this tool

      Add this Chinese Remainder Theorem Calculator to your own page — copy the code below and paste it where you want the tool to appear.

      The embed loads the live calculator in a frame, so it stays up to date automatically. Choose a width, check the code, then copy it. When you publish on WordPress, keep the src pointing at your live tool URL.

      Works in WordPress (Custom HTML block), HTML pages, and most site builders.

      The short answer

      The Chinese Remainder Theorem finds a number x with given remainders modulo two moduli: x congruent to a one modulo m one and a two modulo m two. A solution exists exactly when the remainders agree modulo the greatest common divisor, and it repeats every least common multiple of the moduli.

      • Solution is unique modulo lcm(m1, m2)
      • Exists iff a1 = a2 (mod gcd(m1, m2))
      • Classic example: x=2 mod 3 and x=3 mod 5 gives x=8

      Classic CRT example

      Reference values for this calculator.

      SystemSmallest xRepeats every
      x=2 mod 3, x=3 mod 5815
      x=1 mod 4, x=1 mod 6112

      The formula

      The exact formula this calculator uses — every variable in it is explained in the card below.

      The formula

      x = a1 (mod m1), x = a2 (mod m2); a solution exists iff a1 = a2 (mod gcd(m1,m2)), unique mod lcm(m1,m2)

      Ideas enhancement: reports the whole solution family (x + lcm x k), verifies both congruences on the result card, and — for non-coprime moduli — explains a genuine no-solution case instead of returning a wrong number.

      Worked examples

      Worked examples with the full working shown — try them in the calculator to check.

      Example 1

      worked example

      a1 = 2, a2 = 3, m1 = 3, m2 = 5

      CalculationSteps
      Candidates from the first congruence step by 3; test each modulo 5 until it leaves remainder 3.Result: 8 smallest x >= 0

      Result

      Example 2

      edge: zero remainders, non-coprime

      a1 = 0, a2 = 0, m1 = 4, m2 = 6

      CalculationSteps
      Existence check first: the remainders must agree modulo gcd(4, 6), otherwise the honest answer is 'no solution'.Result: 0

      Result

      Example 3

      edge: larger moduli

      a1 = 17, a2 = 9, m1 = 25, m2 = 12

      CalculationSteps
      The solution repeats every lcm(25, 12), which is why the smallest answer fully describes the family.Result: 117

      Result

      How to use this calculator

      Step 1

      Enter the first remainder and its modulus: x = a1 (mod m1).

      Step 2

      Enter the second remainder and its modulus: x = a2 (mod m2).

      Step 3

      Press Calculate to find the smallest x that satisfies both.

      Step 4

      Add multiples of the lcm shown to get every other solution.

      In short: The Chinese Remainder Theorem is a result in modular arithmetic guaranteeing a solution to simultaneous congruences under stated conditions.

      Frequently asked questions

      What is the Chinese Remainder Theorem?

      It says a system of congruences with coprime moduli has exactly one solution modulo the product of the moduli — and this calculator also handles non-coprime moduli when a solution exists.

      Why did I get 'no solution'?

      When the moduli share a factor, the remainders must agree modulo that factor. If they do not, no number can satisfy both congruences.

      How do I get larger solutions?

      Add the least common multiple of the moduli to the smallest solution, as many times as you like.

      Do the moduli have to be prime?

      No. Coprime (sharing no factor) is enough for a guaranteed solution; primes are just a common special case.

      Why is it called 'Chinese'?

      The problem appears in the Chinese text Sunzi Suanjing (roughly 3rd–5th century CE): a number leaving remainders 2, 3 and 2 on division by 3, 5 and 7 — answer 23. The theorem generalises that puzzle.

      About this calculator

      A Chinese Remainder Theorem calculator: it finds the smallest non-negative number x that leaves remainder a1 on division by m1 and remainder a2 on division by m2, reports the full solution family x + lcm(m1, m2)·k, verifies both congruences, and honestly reports when no solution exists.

      The theorem's power is that separate remainder information pins a number down within a range: knowing x mod 3 and x mod 5 determines x mod 15 uniquely, because 3 and 5 are coprime. The classical Sunzi problem — remainder 2 mod 3, 3 mod 5, 2 mod 7, answer 23 mod 105 — shows the pattern extending to any number of coprime moduli.

      When moduli share a factor, a solution exists only if the remainders agree modulo that factor: x ≡ 1 (mod 4) forces x odd, so x ≡ 2 (mod 6) (even) can never hold simultaneously. Many textbook presentations skip this case; this calculator implements it, because a wrong 'solution' is worse than an honest 'none exists'.

      The search method used here — test a1, a1 + m1, a1 + 2m1, … against the second congruence — is the constructive proof of the theorem in miniature. For classroom-size moduli it is instant; production cryptography instead uses the Garner or extended-Euclid construction for numbers with hundreds of digits.

      Use it for number-theory coursework, calendar and scheduling puzzles (events repeating on different cycles), cryptography teaching examples (RSA uses CRT to speed decryption), gear and phase problems, and the classic 'counting soldiers / eggs in a basket' remainder puzzles.

      How to calculate it yourself

      Step 1

      Reduce each remainder first: replace a with a mod m so remainders sit in 0…m−1.

      Step 2

      List candidates from the first congruence: a1, a1 + m1, a1 + 2m1, …

      Step 3

      Test each against the second congruence; the first that satisfies it is the smallest solution.

      Step 4

      Generalise: add multiples of lcm(m1, m2) for all solutions; if the remainders conflict mod gcd(m1, m2), conclude no solution exists.

      Real-life examples

      Two repeating reminders

      A water filter needs replacing every 3 weeks and a UV lamp every 5 weeks; both were done 2 and 3 weeks into their cycles respectively, and the owner wants the week both fall due together, counting from now in the combined cycle.

      Solve x ≡ 2 (mod 3), x ≡ 3 (mod 5): candidates 2, 5, 8 — 8 mod 5 = 3, so x = 8, repeating every 15.

      Both jobs coincide every 15 weeks, first at week 8 of the cycle.

      Egg basket puzzle

      A stallholder counts eggs: grouping by 4 leaves 0, grouping by 6 leaves 0 — what is the smallest positive basket size consistent with a full-basket display of both counts?

      Solve x ≡ 0 (mod 4), x ≡ 0 (mod 6): the smallest solution is lcm(4, 6) = 12.

      Baskets of 12 (or any multiple of 12) satisfy both counts.

      Ideas & use cases

      • Solve the classic puzzles: remainders 1, 2, 3 on division by 3, 5, 7-style variants — run this two-congruence tool twice (combine the first pair into one mod-lcm congruence, then pair with the third).
      • Schedule design: two maintenance cycles of 4 and 6 days that must coincide — the lcm from the result card is the master cycle to publish.
      • Test inconsistency intuition: try x ≡ 1 (mod 4) with x ≡ 2 (mod 6) and read why the tool refuses — parity makes it impossible, visible at a glance.

      Limitations & sources

      • Two congruences only, with moduli kept small enough for direct search (lcm must stay within safe integer range); very large cryptographic-size moduli are out of scope.

      Sources: Chinese Remainder Theorem: standard number theory references (Rosen, Elementary Number Theory; NIST Digital Library of Mathematical Functions, modular arithmetic)

      Chinese Remainder Theorem Calculator · TinyExe calculator suite Free to use · No sign-up · Instant results