calculator.onl
Categories50

Chinese remainder theorem calculator

Combine integer congruences into one residue and period, including compatible non-coprime moduli. Check which condition first makes a system inconsistent.

A worked example

Keep the first dial at 2 and turn the second. Find the first number that fits both.

x₀23LCM105i (∅)—
aᵢ

mᵢ

Updates as you type

Use a dot or comma for decimals. No thousands separators.

YOUR RESULT

x₀

23

Calculated from your inputs

LCM105
i (∅)—
The numbers, at a glance

Calculations run in your browser.
UNDERSTAND THE RESULT

A little context. A clearer answer.

↑ Back to calculator

When this calculator is useful

The new remainder still has to agree with the other two divisions, so the earliest shared answer moves along the number line. Change “aᵢ” from 2, 3, 2 to 2, 3, 3 and keep the other inputs from the worked example. The value for “x₀” goes from 23 to 38. For a related calculation, try Euclidean modulo calculator.

Think of a maintenance clock that sends a reminder every six days and another that repeats every eight days. Knowing the lengths of the cycles tells you how often an alignment might repeat. Knowing their positions within the cycles tells you when it happens. A congruence records one such condition. If x leaves remainder two when divided by six, write x congruent to two modulo six. The first input list holds these remainders. The second holds the corresponding cycle lengths, in precisely the same order.

For example, a signal is due on days that leave remainder two on division by six and remainder six on division by eight. List a few candidates for the first condition: two, eight, fourteen, twenty, twenty-six and so on. Fourteen also leaves remainder six when divided by eight. The next common day is thirty-eight. The gap is twenty-four, the least common multiple of six and eight. Their product would give forty-eight and would skip every other common day.

There is no guarantee that cycles of overlapping lengths can align. Six and eight have greatest common divisor two. The remainders from a compatible pair must agree modulo two, so both remainders must have the same parity. Replace the six in the second remainder with five. The first condition now insists on an even day and the second insists on an odd day. The empty-set symbol reports this conflict. The last output numbers the input condition that first contradicts the partial system.

The solver merges the conditions in sequence. Suppose the conditions already combined have a solution r and a period M. Every candidate that keeps them true can be written as r plus M times an integer. Substitute that expression into the new congruence. A common factor of M and the new modulus must divide the difference of the two residues. After reducing by this factor, a modular inverse supplies the multiplier needed for the merge. The new period is the least common multiple of the old period and the new modulus.

The result is normalized to the smallest solution greater than or equal to zero. For a clock with period twelve, negative one and eleven are the same clock position. They represent different integers when a separate date range is imposed. To use an answer in a bounded schedule, advance by full periods until the value reaches the beginning of the range, then stop at its end. A reference point matters here. If day zero is Monday, record every condition as a day offset from that same Monday.

The graph compares the normalized input positions as fractions of their own cycles. A remainder of zero appears at the bottom, and the last position in a cycle appears just below one. Equal-looking positions in this graph alone do not establish compatibility because different cycle lengths divide the time axis differently. Read the exact integer outputs for the solution and repeat interval. The input accepts two to twelve pairs, with up to fifteen decimal digits per integer. The solver uses integer arithmetic even when combining cycles produces a period far larger than the individual inputs.

What to enter

InputWhat it meansExample value
aᵢaᵢ2, 3, 2
mᵢmᵢ3, 5, 7

How the calculation works

  1. Combine integer congruences into one residue and period, including compatible non-coprime moduli. Check which condition first makes a system inconsistent.
  2. x ≡ aᵢ (mod mᵢ); M = lcm(m₁, …, mₙ)
  3. Remainders 2, 3 and 2 for moduli 3, 5 and 7 give x₀ = 23 and period 105. Substitution verifies each remainder. The next nonnegative solution is 128.
The formulax ≡ aᵢ (mod mᵢ); M = lcm(m₁, …, mₙ)

A worked example

Remainders 2, 3 and 2 for moduli 3, 5 and 7 give x₀ = 23 and period 105. Substitution verifies each remainder. The next nonnegative solution is 128.

Example you can load

What to enter
Result for this example · x₀23

This is a fixed example; changing the form above does not change these numbers.

Worked comparisons

Start with these reference inputs — aᵢ = 2, 3, 2, mᵢ = 3, 5, 7. The corresponding results, in the order shown on the form, are — x₀ = 23, LCM = 105, i (∅) = —. Each example starts again from the reference inputs. The arrows show exactly which entries to change. All other entries keep their original values.

Case 1. Change one setting or the indicated combination to reproduce this case — aᵢ 2, 3, 2 → 1, 2, 8, mᵢ 3, 5, 7 → 3, 4, 10. Read the following results — x₀ = 58, LCM = 60, i (∅) = —.

Case 2. For the second comparison, restore the reference settings first, then enter — aᵢ 2, 3, 2 → 2, 5, mᵢ 3, 5, 7 → 6, 8. Compare the new answers with the reference result above — x₀ = ∅, LCM = —, i (∅) = 2.

Case 3. For a third check use the following changes — aᵢ 2, 3, 2 → -1, -1, mᵢ 3, 5, 7 → 7, 11. The calculation now gives — x₀ = 76, LCM = 77, i (∅) = —.

Case 4. For the last case enter — aᵢ 2, 3, 2 → 3, 3, mᵢ 3, 5, 7 → 5, 5. Read across the outputs to see which quantities changed and which stayed fixed — x₀ = 3, LCM = 5, i (∅) = —.

Assumptions & limits

Moduli with a common factor can give incompatible remainders.

Reference ·

Frequently asked questions

What does the reported period mean?

Every integer x₀ + k × LCM satisfies the compatible system, for any integer k.

What does the empty-set symbol mean?

The conditions disagree. The index i identifies the first condition incompatible with the preceding conditions in your input order.

Can a remainder be negative?

Yes. The solver normalizes each residue before combining it. Enter the moduli as positive integers of at least two.