Skip to content

Linear Diophantine Equation Calculator

Updated:

Solves the linear Diophantine equation ax + by = c in integers. Enter the coefficients a, b and c to check whether solutions exist, get one particular solution and the full family x = x₀ + (b/g)t, y = y₀ − (a/g)t.

Solve ax + by = c in Integers

Input Fields
a
b
c
If enabled, the result will update automatically when you change any value.

Linear Diophantine Equation Formula

Formula
\[ ax + by = c, \qquad a, b, c \in \mathbb{Z} \] \[ g = \gcd(a, b) \] \[ \text{Integer solutions exist} \iff g \mid c \] \[ x = x_0 + \frac{b}{g}\,t, \qquad y = y_0 - \frac{a}{g}\,t, \qquad t \in \mathbb{Z} \]

Where:

  • \(a\), \(b\) — integer coefficients of \(x\) and \(y\)
  • \(c\) — the integer right-hand side
  • \(g = \gcd(a, b)\) — the greatest common divisor of the coefficients
  • \((x_0, y_0)\) — one particular solution, found from Bézout’s identity \(g = s\,a + t\,b\) by multiplying by \(c/g\)
  • \(t\) — an arbitrary integer parameter that generates all solutions

The equation has integer solutions exactly when \(\gcd(a,b)\) divides \(c\). When it does, there are infinitely many of them: starting from one solution \((x_0, y_0)\), every other solution is obtained by adding \(b/g\) to \(x\) and subtracting \(a/g\) from \(y\) the same number of times \(t\).

Linear Diophantine Equation – Calculation Example

Example: solve \(12x + 18y = 30\) in integers (the calculator’s default values).

\[ \gcd(12, 18): \quad 18 = 1 \cdot 12 + 6, \quad 12 = 2 \cdot 6 + 0 \implies \gcd(12, 18) = 6 \]

\[ 6 \mid 30 \implies \text{solutions exist} \]

\[ \text{Bézout: } 6 = (-1) \cdot 12 + 1 \cdot 18, \qquad \frac{c}{g} = \frac{30}{6} = 5 \]

\[ x_0 = -1 \cdot 5 = -5, \qquad y_0 = 1 \cdot 5 = 5 \]

\[ 12 \cdot (-5) + 18 \cdot 5 = -60 + 90 = 30 \;\checkmark \]

Shifting \(x_0\) into the range \(0 \le x < |b/g| = 3\) gives the equivalent particular solution \((1, 1)\), since \(12 \cdot 1 + 18 \cdot 1 = 30\).

Result: all integer solutions are \(x = 1 + 3t\), \(y = 1 - 2t\) for any integer \(t\); for example \((1, 1)\), \((4, -1)\), \((-2, 3)\).

How to use the calculator

  1. Enter the integer coefficient of \(x\) in the field Coefficient of x (a).
  2. Enter the integer coefficient of \(y\) in the field Coefficient of y (b).
  3. Enter the right-hand side in the field Right-hand side (c).
  4. Read the result blocks: Do integer solutions exist? tells you whether \(\gcd(a,b)\) divides \(c\); One solution (x₀, y₀) gives a verified particular solution; General integer solution gives the complete family with the parameter \(t\); Solution steps shows the Euclidean algorithm, the Bézout coefficients and the reasoning.

All three inputs must be whole numbers (positive, negative or zero). If you enter a non-integer value, the calculator will ask for a whole number, because Diophantine equations are by definition solved in integers only.

What is a linear Diophantine equation?

A Diophantine equation is an equation whose solutions are required to be integers. The linear Diophantine equation \(ax + by = c\) is the simplest kind: it asks for all integer pairs \((x, y)\) that satisfy it exactly, with no fractions or decimals allowed. Such equations appear naturally whenever quantities are indivisible — coins of fixed denominations, boxes of items, people, or tiles.

The central fact is the solvability condition: \(ax + by\) is always a multiple of \(\gcd(a, b)\), so \(c\) must be a multiple of \(\gcd(a, b)\) as well. For example, \(6x + 10y\) is always even, so \(6x + 10y = 7\) has no integer solutions no matter how hard you search. When the condition holds, Bézout’s identity guarantees at least one solution, which the extended Euclidean algorithm finds efficiently.

Interpreting the result: if solutions exist, there are infinitely many of them along an arithmetic progression. The general solution \(x = x_0 + (b/g)t\), \(y = y_0 - (a/g)t\) lists them all — each step of the parameter \(t\) increases \(x\) by \(b/g\) and decreases \(y\) by \(a/g\), keeping \(ax + by\) constant. If you need solutions in a specific range (for example, non-negative ones), substitute a few values of \(t\) and keep those that fit.

Assumptions, limitations and tips

  • Integers only. The coefficients must be whole numbers; the equation is not solved over the rationals or reals. Over the reals, \(ax + by = c\) always has solutions when \(a\) or \(b\) is non-zero — the integer restriction is what makes the problem interesting.
  • Size limits. The computation uses standard arithmetic, so keep the coefficients within the safe integer range (roughly up to 15 digits) to avoid precision issues.
  • Degenerate cases are handled. If \(a = b = 0\), the equation is either always true (\(c = 0\), every pair works) or never true. If exactly one coefficient is zero, the equation has a single variable and the calculator solves it directly.
  • Any particular solution is fine. The pair \((x_0, y_0)\) is not unique — the calculator shifts it to a compact form with \(0 \le x_0 < |b/g|\), but every choice generates the same full solution set through the parameter \(t\).
  • Checking your answer. Always verify by substitution: compute \(a x_0 + b y_0\) and confirm it equals \(c\). The calculator does this check for you in the output.

If your problem involves two linear equations at once instead of one, a system such as \(ax + by = c\), \(dx + ey = f\) is handled with the elimination method rather than with gcd divisibility. Diophantine reasoning also underpins topics like direct variation, where two integer-valued quantities grow in fixed proportion, and it is a classic tool in competition and number-theory problems.

Frequently Asked Questions

How do I solve a linear Diophantine equation by hand?

First compute \(g = \gcd(a, b)\) with the Euclidean algorithm. If \(g\) does not divide \(c\), there are no integer solutions. Otherwise, run the extended Euclidean algorithm to find Bézout coefficients with \(g = sa + tb\), multiply by \(c/g\) to get \(x_0 = s \cdot c/g\) and \(y_0 = t \cdot c/g\), then write all solutions as \(x = x_0 + (b/g)t\), \(y = y_0 - (a/g)t\).

Can negative coefficients or a negative right-hand side be used?

Yes, all three inputs may be negative or zero — only fractions and decimals are rejected. The gcd is always taken of the absolute values, so it is positive. The general solution formulas work unchanged with negative \(a\), \(b\) or \(c\); only the signs of the step sizes \(b/g\) and \(a/g\) in the parameter formulas change.

What is the easiest way to tell if no solution exists?

Check divisibility by the gcd: solutions exist if and only if \(\gcd(a,b)\) divides \(c\). A quick parity test catches many textbook cases — if \(a\) and \(b\) are both even, the left side is always even, so an odd \(c\) makes the equation unsolvable. Similarly, \(6x + 10y\) is always even and also always congruent to multiples of \(\gcd(6,10)=2\) only.

How do I find only non-negative or positive solutions?

The parameter family \(x = x_0 + (b/g)t\), \(y = y_0 - (a/g)t\) gives you a linear condition on \(t\). Solve the two inequalities \(x \ge 0\) and \(y \ge 0\) for \(t\), take the intersection (it is a finite range of integers), and list each value. If the resulting range of \(t\) is empty, no solution with both variables non-negative exists.

Why does the calculator give a different particular solution than my textbook?

Particular solutions are never unique — if \((x_0, y_0)\) works, so does \((x_0 + b/g,\; y_0 - a/g)\). Both answers are correct because they generate the identical full solution set through the parameter \(t\). This calculator shifts \(x_0\) into the compact range \(0 \le x_0 < |b/g|\), which textbooks may not do. Always verify by substituting into \(ax + by\).

What happens if a or b equals zero?

The equation collapses to a single variable. If \(b = 0\), you need \(a \mid c\); then \(x = c/a\) is fixed while \(y\) can be any integer, and symmetrically for \(a = 0\). If both coefficients are zero, the equation is either always true (\(c = 0\), every pair works) or never true. The calculator handles all of these degenerate cases directly.

How is this different from solving a regular linear equation?

Over the real numbers, \(ax + by = c\) with a non-zero coefficient always has solutions — indeed a whole line of them. The Diophantine version demands integer pairs only, which can make it unsolvable (when \(\gcd(a,b) \nmid c\)) or give a discrete, evenly spaced set of solutions along that line instead of a continuum. The step between consecutive solutions is exactly \((b/g, -a/g)\).

Leave a Reply

Your email address will not be published. Required fields are marked *