A linear Diophantine equation is an equation of the form a x + b y = c where a, b, and c are given integers, and the goal is to find integer solutions x and y. Unlike ordinary linear equations over the real numbers, you are not allowed to use fractions or decimals for x and y. Only integer pairs are valid solutions.
These equations are named after Diophantus of Alexandria and are a core topic in elementary number theory. They appear in many settings: counting and partition problems (such as coin-change puzzles), cryptography, modular arithmetic, and algorithm analysis. This calculator focuses on single linear equations in two variables.
Not every equation of the form a x + b y = c has an integer solution. The key quantity is the greatest common divisor (gcd) of a and b. Denote g = gcd(a, b).
The fundamental criterion is:
g divides c (written g | c), then there are infinitely many integer solutions (x, y).g does not divide c, then there is no integer solution.This can be expressed precisely as:
The calculator automatically checks this condition. If the gcd does not divide c, it will state that no integer solution exists.
The extended Euclidean algorithm is the main tool used internally by this solver. It not only computes g = gcd(a, b), but also finds integers u and v such that:
a u + b v = g.
This identity is called Bézout's relation. Once we know such integers u and v, we can scale the identity to obtain a particular solution of the target equation, provided that g divides c.
If c is a multiple of g, write c = g k for some integer k. Multiplying Bézout's relation by k gives:
a (k u) + b (k v) = g k = c,
so a particular solution is:
x₀ = k u = (c / g) u, y₀ = k v = (c / g) v.
Once one solution (x₀, y₀) is known, all solutions can be described parametrically. Let t be any integer. Then every solution can be written as:
x = x₀ + (b / g) ty = y₀ - (a / g) tThe calculator reports one particular solution and the corresponding parametric family. Each integer value of t generates a different integer pair (x, y) that satisfies the equation.
a x + b y = c.x into the field labeled Coefficient a.y into the field labeled Coefficient b.t that describes all integer solutions.To generate specific solutions, substitute integer values of t (such as t = -2, -1, 0, 1, 2) into the general formulas for x and y.
Consider the equation:
12 x + 18 y = 30.
gcd(12, 18) = 6.6 divides 30, so solutions exist.u and v such that 12 u + 18 v = 6. One such pair is u = -1, v = 1, since 12 (-1) + 18 (1) = 6.c = 30. Because 30 / 6 = 5, set x₀ = 5 u = 5 (-1) = -5 and y₀ = 5 v = 5 (1) = 5.12 (-5) + 18 (5) = -60 + 90 = 30, so (x₀, y₀) = (-5, 5) is a valid solution.Now describe all solutions. With g = 6, the general solution is:
x = -5 + (18 / 6) t = -5 + 3 ty = 5 - (12 / 6) t = 5 - 2 tEach integer t yields a different solution pair. For example:
t = 0: x = -5, y = 5t = 1: x = -2, y = 3t = -1: x = -8, y = 7Consider:
6 x + 10 y = 7.
gcd(6, 10) = 2.2 divides 7. It does not.Therefore, no integer pair (x, y) can satisfy the equation. The calculator will display that there is no integer solution. This is not a numerical failure; it reflects a genuine mathematical impossibility under the integer constraint.
Sometimes one coefficient is zero, such as:
0 x + 9 y = 27.
Here a = 0, b = 9, c = 27. The equation simplifies to 9 y = 27. The gcd is gcd(0, 9) = 9, and 9 divides 27, so integer solutions exist.
Solving directly, y = 3, and x can be any integer. Written in parametric form, one convenient solution is x₀ = 0, y₀ = 3, and all solutions are:
x = t (any integer)y = 3The calculator handles this type of degenerate case by following the same gcd logic.
| Case | Condition on gcd(a, b) and c | Number of integer solutions | Behavior in the calculator |
|---|---|---|---|
| Standard solvable | gcd(a, b) divides c |
Infinitely many solutions | Shows gcd, one particular solution, and parametric family in terms of t |
| No solution | gcd(a, b) does not divide c |
No integer solutions exist | Clearly indicates that there is no integer solution for the given coefficients |
| One coefficient zero | Either a = 0 or b = 0, but not both, and the nonzero coefficient divides c |
Infinitely many solutions (one variable fixed, the other free) | Reduces internally to a single-variable equation and returns a correct parametric form |
| Both coefficients zero | a = 0 and b = 0 |
Either no solution (if c ≠ 0) or every integer pair (if c = 0) |
Edge case: see notes in the assumptions and limitations below |
Linear Diophantine equations model many integer-constrained problems. A few examples:
a and b and want a total of c units, the integer solutions represent ways to combine coins to reach c.a and b. An equation a x + b y = c models how many groups of each size are needed to reach a target total.a x ≡ c (mod m) often reduces to solving a linear Diophantine equation in two variables.In these contexts you often care about extra constraints, such as requiring x ≥ 0 and y ≥ 0 (you cannot use a negative number of coins). The calculator provides the full integer solution set; you then restrict to values of t that make x and y satisfy your practical constraints.
a, b, and c. If you enter decimals, they are treated according to how your browser handles the numeric input, and the mathematical theory described here assumes integers.x and y. It does not directly solve systems of several linear Diophantine equations or problems with three or more variables.0 x + 0 y = c. If c ≠ 0, there is no solution. If c = 0, every integer pair (x, y) is a solution. Some implementations choose to treat this as a special case and may simply report that the equation is indeterminate or that every pair is a solution.a, b, and c are fully supported by the theory. The gcd is always taken to be non-negative, and sign changes are absorbed into the particular solution.0 ≤ x ≤ 100), you must manually choose appropriate integer values of t that satisfy those bounds.This means that gcd(a, b) does not divide c. There is no pair of integers (x, y) that satisfies the equation exactly. Adjusting the coefficients slightly (for example, changing c to a nearby multiple of gcd(a, b)) may make the equation solvable.
The calculator itself does not enforce sign constraints. However, once you have the general solution in terms of t, you can identify which integer values of t produce positive (or non-negative) values of x and y.
If a = 0, the equation reduces to b y = c. An integer solution exists only if b divides c. In that case, y = c / b and x can be any integer. The situation is symmetric if b = 0.
Yes, computing the modular inverse of a modulo m (when it exists) is equivalent to solving a x + m y = 1. If the calculator finds integer x and y, then x is a modular inverse of a modulo m.