Linear Congruence Calculator & Solution Timeline
Enter up to five congruences, including moduli with shared factors. Follow the greatest common divisor checks, find the first matching integer from any start, and inspect the repeating solutions on a timeline.
Solve a system of linear congruences
Find the repeating integer solutions and see where the rows overlap.
Congruences and window
For each equation ax ≡ b (mod m), enter a, b and m on one line, separated by commas or tabs.
The rows share a repeating solution.
Common solutions
x ≡ 14 (mod 36)
First match at or after the window start 14.
Solution timeline
Showing integers from 0 through 59.
10 row matches · 2 common matches
x ≡ 2 (mod 6)
0
Row does not match · no common match
Check the arithmetic
Show reductions and merges
Row 1 · 4x ≡ 8 (mod 24)
GCD 4 · b leaves remainder 0.
GCD check (4) × (1) + 24 × (0) = 4.
x ≡ 2 (mod 6)
Row 2 · 1x ≡ 5 (mod 9)
GCD 1 · b leaves remainder 0.
GCD check (1) × (1) + 9 × (0) = 1.
x ≡ 5 (mod 9)
Row 3 · 1x ≡ 2 (mod 4)
GCD 1 · b leaves remainder 0.
GCD check (1) × (1) + 4 × (0) = 1.
x ≡ 2 (mod 4)
Merge with row 2
x ≡ 2 (mod 6) and x ≡ 5 (mod 9).
Period GCD 3 · residue difference 3 · remainder 0.
x ≡ 14 (mod 18)
Merge with row 3
x ≡ 14 (mod 18) and x ≡ 2 (mod 4).
Period GCD 2 · residue difference -12 · remainder 0.
x ≡ 14 (mod 36)
Export the congruence worksheet
Save exact reductions, merge steps and every matching integer in this window.
View CSV text
How to use this calculator
- Enter a, b and m for each linear congruence. Use commas or tabs and one row per equation.
- Enter a starting integer and how many consecutive integers to show.
- Read the common residue and period or the failed divisibility check. Inspect individual rows and integers with the timeline sliders.
- Open the arithmetic ledger to check the reductions and merges, or export the exact values and matching integers.
The Formula
The mathematical logic powering this calculation is:
For ax ≡ b (mod m), let g = gcd(a,m). A solution exists exactly when g divides b. The extended Euclidean algorithm gives coefficients u and v with au + mv = g. If the row is solvable, x ≡ u(b/g) (mod m/g) describes all its integer solutions. The calculator reports the least nonnegative representative. A reduced period of 1 means every integer satisfies the row.
To merge x ≡ r (mod M) with x ≡ s (mod N), write x = r + Mk. Substitution gives Mk ≡ s−r (mod N). The merge is possible exactly when gcd(M,N) divides s−r. A successful merge repeats every lcm(M,N) = MN/gcd(M,N). Repeat with each remaining row. The first failed row or merge identifies a nonzero remainder, a direct reason the full system has no solution.
To find the first solution at or above start L, add the least nonnegative remainder of r−L modulo the common period to L. That answer can be outside the displayed window. The timeline displays each matching integer in the 1–60 position window. The complete answer remains the residue class.
Enter one to five rows with a, b and positive modulus m per row. Use up to 18 digits per input integer and signs on a, b and the window start. All arithmetic and CSV values use exact integers, even when the combined period exceeds 18 digits.Worked Example
If you input:
- Rows: 4x ≡ 8 (mod 24), x ≡ 5 (mod 9), x ≡ 2 (mod 4)
- Window: 0 through 59
Result:
The reduced rows share x ≡ 14 (mod 36). The first solution at or after 0 is 14. The timeline shows both 14 and 50.
Frequently Asked Questions
How do you solve a linear congruence?
Compute gcd(a,m). If it divides b, divide the coefficient, right side and modulus by it. The reduced coefficient then has an inverse when the reduced modulus exceeds 1. Use that inverse to find the residue.
Do all moduli have to be coprime?
Shared factors are allowed. Two reduced residues must agree modulo the greatest common divisor of their periods. A successful merge repeats with the least common multiple of those periods.
Why can there be solutions with an empty timeline?
The timeline shows a finite interval. The first solution at or after its start can lie beyond the last displayed integer. The common rule still describes all integer solutions.
What happens when the coefficient is zero?
Every integer solves the row if the modulus divides the right side. Otherwise the row has no solution.
Can the first solution be negative?
Yes. The canonical residue is always nonnegative, while the first solution relative to a negative window start can also be negative.
Similar Calculators
GCF Calculator
Find the greatest common factor (GCF) of two or more integers.
Prime Factorization Calculator
Find the prime factors of any whole number and express it as a product of prime numbers.
Repeating Decimal Calculator & Remainder Cycle
Convert repeating decimals to reduced fractions or find the shortest decimal period of a fraction. Trace the exact remainders and inspect any digit.
Divisibility Rules Calculator & Missing Digits
Test a whole number against several divisors or solve for missing digits. See exact match counts, possible digits and a step-by-step remainder trace.
