Professional Documents
Culture Documents
1
Named after Diophantus of Alexandria who studied such equations in the 3rd Century
AD.
2
Here we will just consider the linear Diophantine equation. We start with
some examples that give an indication of when this equation has a solution.
3x + 4y = 19.
This has a solution x = 1, y = 4 (and from this solution we can construct
infinitely many solutions x = 1 + 4t and 4 − 3t where t is an integer.) On
the other hand,
4x + 6y = 13
has no integral solutions, because if x and y are integers then the left side
of the equation is even, but 13 is odd. As anther example
6x − 9y = 14
has no integral solutions as the left side is dividable by 3, but the right side
is not. It turns out this problem of the left side of ax + by = c having
a divisor that the right side does not have is the only obstruction to the
equation having integral solutions.
Theorem 1 (Solution to the linear Diophantine equation). If a, b, and c
are integers with a and b both nonzero, then
ax + by = c
has a solution if and only if
gcd(a, b) | c.
If (x0 , y0 ) is one solution, then the general solution2 is
bt at
x = x0 − , y = y0 + . (1)
gcd(a, b) gcd(a, b)
Remark 2. In the this theorem it is often convenient to use the following
notation. Let
a b
a0 = , b0 = .
gcd(a, b) gcd(a, b)
Then the general solution is
x = x0 − a0 t, y = y0 + b0 t.
You will also often see the general solution written with t replaced by −t,
that is
x = x0 + a0 t, y = y0 − b0 t.
This gives the same set of solutions, just listed in the reverse order.
Problem 1. Prove Theorem 1 along the following lines. First show the easy
direction, that is if ax + by = c has a solution, then gcd(a, b) | c.
In the other direction we assume that gcd(a, b) | c and show that the
equation has a solution. To simplify notation set
d = gcd(a, b).
2By “general solution” we mean that this gives all solutions.
3
and we stop here as 2 | 10. Now keep doing backward substations in this to
get
(2) = (52) − 5(10) = (52) − 5 (62) − (52)
= −5(62) + 6(52) = −5(62) + 6 (114) − 1(62)
= 6(114) − 11(62) = 6(114) − 11 (632) − 5(144)
= −11(632) + 61(114) = −11(632) + 61 (2642) − 4(632)
= 61(2642) − 255(632)
Therefore x0 = 61 and y0 = −255 is solution to ax + by = 2642x + 632y = 2
and the general solution is
b 632
x = x0 − t = 61 − t = 61 − 316t
gcd(a, b) 2
a 2642
y = y0 + t = −255 + t = −255 + 1321t.
gcd(a, b) 2
Example 4. Find all solutions to the Diophantine equation
324x − 142y = 30.
We start by using the Euclidean algorithm to find the greatest common
divisor of 324 and −142.
(40) = (324) + 2(−142)
(18) = (−142) + 4(40)
(4) = (40) − 2(18)
(2) = (18) − 4(4)
Thus gcd(324, −142) = 2 and 2 | 30, whence this Diophantine has a solution.
Now work backwards,
(2) = (18) − 4(4) = (18) − 4 (40) − 2(18)
= −4(40) + 9(18) = −4(40) + 9 (−142) + 4(40)
= 9(−142) + 32(40) = 9(−142) + 32 (324) + 2(−142)
= 32(324) + 73(−142)
Therefore
324(32) − 142(73) = 2
Multiply this by 15 to get
324(15 · 32) − 142(15 · 73) = 15 · 2,
that is
324(480) − 142(1095) = 30.
6
Thus x0 = 480 and y0 = 1095 is one solution to the equation. The general
solution is then
−142
x = 480 − t = 480 + 71t
2
324
y = 1095 + t = 1095 + 162t
2
where t can be any integer.
Example 5. A samll post office has only 13¢ and 17¢ stamps. How many
ways can a postage of $5.76 be done?
Let x be the number of 13¢ stamps and y the number of 17¢ stamps.
Then the problem is equivalent to finding all solutions to the Diophantine
equation
13x + 17y = 576
with x ≥ 0 and y ≥ 0. Clearly gcd(13, 17) = 1 | 576 so there will be
solutions in integers (which does not necessarily mean there are solutions in
nonnegative integers). First use the Euclidean algorithm to find solutions
to Bézout’s equation.
(4) = (17) − (13)
(1) = (13) − 3(4).
and therefore
(1) = (13) − 4(4) = (13) − 3 (17) − (13) = 4(13) − 3(17).
Thus
13(4) + 17(−3) = 1.
Multiply by 576 to get
13(4 · 576) + 17(−3 · 576) = 13(2304) + 17(−1728) = 576.
This gives the pair x0 = 2304 and y0 = −1728 as one solution. The general
solution is
x = 2304 − 17t, y = −1728 + 13t.
We are only interested in solutions that are nonnegative.
2304
x = 2304 − 17t ≥ 0 =⇒ t≤ = 135.529 . . .
17
Which implies t ≤ 135 because t is an integer. Also
1728
y = −1728 + 13t ≥ 0 =⇒ t≥ = 132.923 . . .
13
which implies t ≥ 133. Thus 133 ≤ t ≤ 135. So only the values t = 133,
t = 134, and t = 135 give solutions to our problem. These give
(x, y) = (2304 − 17 · 133, −1728 + 13 · 133) = (43, 1)
(x, y) = (2304 − 17 · 134, −1728 + 13 · 134) = (26, 14)
(x, y) = (2304 − 17 · 135, −1728 + 13 · 135) = (9, 27)
7
for the number, x, of 13¢ stamps and, y, the number of 17¢ stamps.
This suggests a more general problem. If a, b, and c are positive, are there
conditions that guarantee that ax + by = c has a nonnegative solution?
Proposition 6 (Sylvester, 1884). If a, b, and c be positive integers with
gcd(a, b) = 1 and c ≥ (a − 1)(b − 1). Then there are nonnegative integers x
and y with
ax + by = c.
This is sharp in the sense that if c = (a − 1)(b − 1) − 1 = ab − a − b then the
equation has no solution in nonnegative integers.
Proof. Let (x0 , y0 ) be the an integral solution to ax + by = c. Then the
general solution is
x = x0 − bt, y = y0 + at.
By the division algorithm we can choose t such that x1 := x0 − bt satisfies
0 ≤ x1 ≤ b − 1. Let y1 = y0 + at. Then ax1 + by1 = c and x1 ≥ 0. So it is
enough to show y1 ≥ 0.
by1 = c − ax1
≥ (a − 1)(b − 1) − ax1
≥ (a − 1)(b − 1) − a(b − 1)
= (b − 1)(a − 1 − a)
= −(b − 1).
Divide by b
(b − 1) 1
y1 ≥ − = −1 + > −1.
b b
As y1 is an integer this implies y1 ≥ 0. Therefore ax + by = c has the
nonnegative solution (x, y) = (x1 , y1 ).
For the second part of the Proposition, assume, towards a contradiction,
that
ax + by = ab − a − b
has a solution with x, y ≥ 0. Rewrite as
ab = a(x + 1) + b(y + 1).
This implies that a | b(y + 1) and as gcd(a, b) = 1 this farther implies
a | (y + 1). As y ≥ 0 this yields that (y + 1) ≥ a. Likewise b | a(x + 1),
gcd(a, b) = 1 gives that b | (x + 1) ≥ 1 and x ≥ 0 therefore gives (x + 1) ≥ b.
This yields
ab = a(x + 1) + b(y + 1) ≥ ab + ab = 2ab
the required contradiction.
8
Problem 4. For the following pairs (a, b) of integers use the Euclidean
algorithm to find integers x and y that solve the Bézout equation ax + by =
gcd(a, b).
(a) (a, b) = (16, 12) (b) (a, b) = (8, −3) (c) (a, b) = (−12, 10)
(d) (a, b) = (−21, −28) (e) (a, b) = (653, 291) (f) (a, b) = (741, −432)
(g) (a, b) = (−534, 972) (h) (a, b) = (−548, −362).
Problem 5. For the following linear Diophantine equation equations deter-
mine if they have solutions. If they do, give the general solution.
(a) 6x + 4y = 12 (b) 6x − 4y = 12 (c) 37x − 47y = 15
(d) 432x − 974y = 3 (e) 432x − 974y = 14 (f) 31x + 19y = 102
(g) 20x + 34y = 1 (h) 21x + 34y = 1
Problem 6. Find all nonnegative integral solutions to the following:
(a) 3x + 4y = 100 (b) 12x + 18y = 204 (c) 7x − 9y = 3
1.1. The linear Diophantine equation in three or more variables.
Under some conditions on the coefficients it is very easy to adapt what
we have just done to finding the general solution to the linear Diophantine
equation in three or more variables.
Example 7. Consider
5x + 2y + 3z = 12.
We rewrite this as
5x + 2y = 12 − 3z.
As gcd(5, 2) = 1 | (12 − 3z) for any value of z, this is solvable for x and y
for any value of z. We see by inspection that
5(1) + 2(−2) = (1).
Multiply by 12 − 3z to get
(12 − 3z) + 2(−24 + 6z) = (12 − 3z).
Thus (x0 , y0 ) = (12 − 3z, −24 + 6z) is a particular solution to 5x + 2y =
12 − 3z. Whence the general solution is
x = 12 − 3z − 2t, y = −24 + 6z + 5t
with t ∈ Z. This can be made to look a bit more aesthetic by introducing
a new variable s for z, that is set z = s and writing the general solution to
the original equation in the more symmetric form.
x = 12 − 3s − 2t
y = −24 + 6s + 5t
z=s
The condition that made this easy was gcd(5, 2) = 1 so that 5x+2y = 12−3z
has a solution for all z.
Problem 7. Find the general solution to the following linear Diophantine
equations.
9