Modular Linear Equation Calculator
Solve ax ≡ b (mod m) and list solutions when they exist. This educational calculator shows the formula, result, and step-by-step interpretation.
Calculator
What this calculator teaches
Modular linear equations appear in number theory, congruences, and cryptographic examples.
Use the result as a learning aid. For classwork, still show the formula and intermediate reasoning so the final answer is not just a black-box number.
When a Linear Congruence Has Solutions
The congruence ax ≡ b (mod m) asks for integers x whose product ax differs from b by a multiple of m. Unlike ordinary algebra, division by a is not always legal modulo m because a may not have a multiplicative inverse. The key test is g = gcd(a,m): solutions exist exactly when g divides b.
If g divides b, divide a, b, and m by g to obtain a reduced congruence a′x ≡ b′ (mod m′) with gcd(a′,m′) = 1. Now a′ has a modular inverse, so one reduced solution is x0 ≡ (a′)−1b′ (mod m′). In the original modulus m there are exactly g distinct residue-class solutions.
| Step | Rule | Purpose |
|---|---|---|
| Solvability | g = gcd(a,m), require g | b | Determines whether any solution exists |
| Reduction | a′=a/g, b′=b/g, m′=m/g | Makes a′ invertible modulo m′ |
| Base solution | x0 ≡ (a′)−1b′ mod m′ | Finds one residue class |
| All solutions | x = x0 + km′, k=0,…,g−1 | Lists distinct solutions modulo m |
This gcd structure explains why cancellation in modular arithmetic requires care. A common factor can be cancelled only when the modulus is reduced consistently as part of the congruence.
Formula & Symbols
| Concept | Formula or rule |
|---|---|
| Equation | ax ≡ b (mod m) |
| Solvability | gcd(a,m) divides b |
Worked example
Common mistakes
Keep lists comma separated, matrices as rows separated by semicolons, and modular inputs as integers.
Some methods require positive probabilities, valid moduli, independent trials, or small educational input sizes.
Modular division means multiplication by an inverse. If gcd(a,m) ≠ 1, a has no inverse modulo m, so use the gcd reduction method instead.
When g = gcd(a,m) > 1 and g divides b, the original congruence has g distinct solutions modulo m. Generate all of them using spacing m/g.
FAQ
Related calculators
These links will work after the calculators are registered in the final Math layout update.
Formula Explorer connections
Interpretation: This formula describes an algebraic relationship among variables, functions, equations, roots or sequences. Assumption: Respect the expression’s domain and excluded values. Check roots in the original equation because transformations can introduce extraneous solutions.