Linear Diophantine Equation Calculator
- gcd(12, 18) = 6, which divides 30, so solutions exist; the extended Euclidean algorithm gives 12 x (-1) + 18 x (1) = 6.
- Scaling by 5 and shifting along the solution line to the smallest non-negative x gives x = 1, y = 1; check: 12 x 1 + 18 x 1 = 30.
- Every solution is x = 1 + 3t, y = 1 - 2t for an integer t, because stepping x by b/g must be balanced by stepping y by a/g.
- Requiring both values to stay non-negative leaves 1 solution(s); beyond that range one of the two turns negative.
This linear diophantine equation calculator solves equations of the form ax + by = c, where a, b and c are integers and you want integer values for x and y. It checks whether a solution exists and, when one does, gives you a particular solution together with the full family of solutions. For example, 12x + 18y = 30 has gcd 6 and the smallest non-negative solution x = 1, y = 1. Its full solution family is x = 1 + 3t, y = 1 - 2t, and only 1 solution keeps both unknowns non-negative. With coprime coefficients, 7x + 11y = 100 has the solution x = 8, y = 4 and the family x = 8 + 11t, y = 4 - 7t. Not every equation works: 6x + 10y = 7 has no integer solution at all, because gcd 2 does not divide 7, and the nearest solvable right-hand sides are 6 and 8.
The method behind the calculator is the standard test for this kind of problem: a solution exists exactly when gcd(a, b) divides c. That is the check every linear Diophantine problem starts with, which is why the tool applies it first and then builds the solution family from there. On this page you will find the formula, step-by-step workings, worked examples and sources, so you can follow each stage of the calculation yourself rather than just reading off an answer.
Worked examples
12x + 18y = 30
(12 · 18 · 30)
| Particular solution (smallest x >= 0) | x = 1, y = 1 |
| gcd(a, b) | 6 |
| General solution | x = 1 + 3t, y = 1 - 2t |
| Solutions with x, y both >= 0 | 1 |
7x + 11y = 100
(7 · 11 · 100)
| Particular solution (smallest x >= 0) | x = 8, y = 4 |
| gcd(a, b) | 1 |
| General solution | x = 8 + 11t, y = 4 - 7t |
| Solutions with x, y both >= 0 | 1 |
6x + 10y = 7 has no solution
(6 · 10 · 7)
| Integer solutions | No solution |
| gcd(a, b) | 2 |
| Remainder of c on division by the gcd | 1 |
| Nearest solvable c (multiple of the gcd) | 6 |
How linear Diophantine equations are solved
Every linear Diophantine problem starts with the same test: a solution to ax + by = c exists exactly when gcd(a, b) divides c. Apply that test before doing any algebra. For 6x + 10y = 7, the gcd is 2, and 2 does not divide 7, so the equation has no integer solution at all. No amount of rearranging will rescue it. The nearest solvable right-hand sides are 6 and 8, which is a useful way to see how the divisibility condition cuts the number line into reachable and unreachable values. A linear diophantine equation calculator runs this check first, so it can tell you immediately whether a solution exists rather than searching for one that cannot be there.
When the test passes, the extended Euclidean algorithm does the work. It runs the Euclidean algorithm on the two coefficients, tracking at each step how the current remainder is built from the original pair. At the end it returns the gcd along with two integers that combine with the coefficients to produce that gcd. Those two integers give one particular solution, and scaling them by c divided by the gcd gives a particular solution to the original equation.
Work through 12x + 18y = 30. The gcd of 12 and 18 is 6, and 6 divides 30, so solutions exist. The extended Euclidean algorithm expresses 6 as a combination of 12 and 18, and scaling by 30/6 = 5 produces the particular solution x = 1, y = 1, which is the smallest non-negative solution. From there the full solution family is x = 1 + 3t, y = 1 - 2t, where t is any integer. The step sizes come from dividing the coefficients by the gcd: 18/6 = 3 and 12/6 = 2.
The family shows the shape of the answer set. For 12x + 18y = 30, only one value of t keeps both unknowns non-negative, so exactly one solution sits in the non-negative range. A similar pattern appears with coprime coefficients: 7x + 11y = 100 has the solution x = 8, y = 4 and the family x = 8 + 11t, y = 4 - 7t. Because the coefficients share no common factor, the steps are the full coefficients themselves, and the solutions are spaced farther apart.
Putting it together, the method is short: compute the gcd, test whether it divides c, use the extended Euclidean algorithm to get one solution, then add multiples of b/gcd and subtract multiples of a/gcd to describe every solution. The calculator applies these steps and reports the particular solution, the general family, and how many solutions keep both unknowns non-negative.
The general solution family
Once a linear Diophantine equation calculator has confirmed that gcd(a, b) divides c, the next job is to describe every solution, not just one. The key idea is that a single known solution acts as an anchor, and all other solutions are reached by stepping away from it in a fixed direction. For 12x + 18y = 30, the gcd is 6, and the smallest non-negative solution is x = 1, y = 1. From that anchor, the full solution family is x = 1 + 3t, y = 1 - 2t, where t is any integer. Each increase of t by 1 raises x by 3 and lowers y by 2, so the equation stays balanced.
The same structure appears when the coefficients share no common factor. For 7x + 11y = 100, the coefficients are coprime, and one solution is x = 8, y = 4. The family is x = 8 + 11t, y = 4 - 7t. Here the steps are larger because the coefficients are larger, but the pattern is identical: one coordinate moves up while the other moves down, and the pair always returns to the same total.
Why are the steps b/g and a/g? In the first example, b = 18 and g = 6, so the step in x is 18/6 = 3; a = 12 and g = 6, so the step in y is 12/6 = 2. In the second, b = 11 and g = 1, giving a step of 11 in x, and a = 7 with g = 1, giving a step of 7 in y. Dividing by the gcd strips out the shared factor, leaving the smallest whole-number trade that keeps the equation true. A larger step would skip valid solutions; a smaller one would break the equality.
This family view also explains why some equations have no solutions to organize. For 6x + 10y = 7, the gcd is 2, and 2 does not divide 7, so there is no integer solution at all. The nearest solvable right-hand sides are 6 and 8, which sit on either side of 7. That is the test every linear Diophantine problem starts with: a solution exists exactly when gcd(a, b) divides c.
The family also shows how many solutions satisfy extra conditions. For 12x + 18y = 30, only 1 solution keeps both unknowns non-negative, even though the family itself is infinite. A linear diophantine equation calculator uses the step structure to count or list those restricted cases quickly.
- 12x + 18y = 30: gcd 6, anchor x = 1, y = 1, family x = 1 + 3t, y = 1 - 2t
- 7x + 11y = 100: coprime coefficients, anchor x = 8, y = 4, family x = 8 + 11t, y = 4 - 7t
- Step in x is b/g; step in y is a/g
- 6x + 10y = 7: gcd 2 does not divide 7, so no integer solution; nearest solvable right-hand sides are 6 and 8
When there is no solution
Before you reach for a linear diophantine equation calculator, it helps to know the one test that decides whether any answer exists at all. A solution to ax + by = c exists exactly when gcd(a, b) divides c. This is the test every linear Diophantine problem starts with, and it is worth understanding why it works. Whatever integers you choose for x and y, the left side is always a multiple of gcd(a, b), because that divisor is built into both coefficients. So if c is not a multiple of the gcd, no pair of integers can ever make the equation balance. The arithmetic rules out the problem before any searching begins.
The simplest way to see this is with 6x + 10y = 7. The gcd of 6 and 10 is 2, and 2 does not divide 7. Whatever integers you pick, 6x is even and 10y is even, so their sum must be even too. The value 7 is odd, so it is simply unreachable. No amount of trial and error will produce a solution, and a calculator that respects the gcd test will tell you so immediately rather than searching forever. The nearest solvable right-hand sides are 6 and 8: both are even, so both can be hit, while 7 sits between them as a gap that no integer pair can fill.
Contrast that with 12x + 18y = 30. Here the gcd is 6, and 6 does divide 30, so solutions exist. The smallest non-negative solution is x = 1, y = 1, and the full solution family is x = 1 + 3t, y = 1 - 2t. As t varies over the integers, most values push one unknown negative; only one solution keeps both unknowns non-negative. Coprime coefficients behave the same way but with less friction. For 7x + 11y = 100, the gcd is 1, which divides every integer, so a solution is guaranteed. One is x = 8, y = 4, and the family is x = 8 + 11t, y = 4 - 7t.
These examples show the two failure modes people confuse. The first is a hard impossibility: the gcd does not divide c, and there is no integer solution whatsoever. The second is a matter of constraints: solutions exist, but if you require x and y to be non-negative, only some members of the family qualify, and sometimes just one. A good linear diophantine equation calculator checks the gcd first, reports "no solution" when the divisibility test fails, and otherwise shows the full family so you can see which values of t keep the unknowns in the range you need. Knowing the gcd rule means you can predict the verdict yourself before typing a single number.
Counting non-negative solutions
Once you have the full family of integer solutions to ax + by = c, the next question in many applications is how many of those solutions keep both x and y at zero or above. A linear diophantine equation calculator answers this by taking the general family and clipping it to the region x ≥ 0, y ≥ 0. The arithmetic is simple: each unknown is a linear expression in the parameter t, so requiring both to be non-negative gives two inequalities on t, and the count of non-negative solutions is the number of integers t that satisfy both at once.
Take 12x + 18y = 30. The greatest common divisor of 12 and 18 is 6, and 6 divides 30, so solutions exist. The smallest non-negative solution is x = 1, y = 1, and the full solution family is x = 1 + 3t, y = 1 - 2t for integer t. Now impose x ≥ 0 and y ≥ 0. From x = 1 + 3t ≥ 0 we need t ≥ -1/3, so t ≥ 0. From y = 1 - 2t ≥ 0 we need t ≤ 1/2, so t ≤ 0. The only integer t meeting both conditions is t = 0, which returns x = 1, y = 1. This family therefore leaves exactly 1 non-negative solution.
The second worked family behaves the same way. For 7x + 11y = 100 the coefficients are coprime, so the gcd test passes immediately. One solution is x = 8, y = 4, and the family is x = 8 + 11t, y = 4 - 7t. Requiring x ≥ 0 gives t ≥ -8/11, so t ≥ 0. Requiring y ≥ 0 gives t ≤ 4/7, so t ≤ 0. Again only t = 0 survives, and this family also leaves exactly 1 non-negative solution, namely x = 8, y = 4.
Larger right-hand sides change the picture. Increasing c shifts the family and widens the window of allowed t values, so more non-negative solutions appear. The clipping method stays the same: solve each inequality for t, take the overlap, and count the integers inside it. It is worth remembering that this counting step only makes sense after the existence test. A solution exists exactly when gcd(a, b) divides c, the check every linear Diophantine problem starts with. For example, 6x + 10y = 7 has no integer solution at all, because gcd 2 does not divide 7. For that impossible equation the nearest solvable right-hand sides are 6 and 8, so there is no family to clip and the count of non-negative solutions is zero.
- 12x + 18y = 30: family x = 1 + 3t, y = 1 - 2t; the only t keeping both non-negative is t = 0, so exactly 1 non-negative solution.
- 7x + 11y = 100: family x = 8 + 11t, y = 4 - 7t; again only t = 0 qualifies, so exactly 1 non-negative solution.
- 6x + 10y = 7: gcd 2 does not divide 7, so no integer solution exists and there is nothing to count; the nearest solvable right-hand sides are 6 and 8.
FAQs
How do I solve 12x + 18y = 30 in integers?
First find gcd(12, 18), which is 6. Because 6 divides 30, integer solutions exist. The smallest non-negative solution is x = 1, y = 1, since 12(1) + 18(1) = 30. From there, the general solution adds and subtracts multiples of the reduced coefficients to produce every other integer solution.
When does ax + by = c have no solution?
The equation has no integer solution when gcd(a, b) does not divide c. For example, 6x + 10y = 7 fails because gcd(6, 10) = 2, and 2 does not divide 7. No choice of integers x and y can make the left side odd, so the equation is unsolvable in integers.
What is the general solution?
Once you have one particular solution (x0, y0), every integer solution is x = x0 + (b/g)t and y = y0 - (a/g)t, where g = gcd(a, b) and t is any integer. For 7x + 11y = 100, that gives x = 8 + 11t and y = 4 - 7t.
How many solutions does 7x + 11y = 100 have?
There are infinitely many integer solutions, generated by x = 8 + 11t and y = 4 - 7t as t ranges over the integers. However, only one solution has both x and y non-negative: x = 8, y = 4. Increasing or decreasing t pushes one of the two variables below zero.
What is the extended Euclidean algorithm used for?
The extended Euclidean algorithm finds integers that satisfy a·x + b·y = gcd(a, b). That pair is the seed solution. Scaling it by c divided by gcd(a, b) turns it into a particular solution of the full equation ax + by = c, which you then expand into the general solution.
Can coefficients be negative or zero?
The method on this page is stated for positive coefficients. Negative signs can be absorbed into the unknowns, so a negative coefficient does not change the underlying approach. A zero coefficient reduces the equation to a divisibility question, since one variable drops out entirely and the other must divide the constant exactly.