Diophantine Equations

Study Sheet

Diophantine Equations

Integer solutions: linear equations, factoring tricks and bounding

Linear Diophantine Equations

Concept
ax+by=cax + by = c

The equation ax+by=cax + by = c has integer solutions iff gcd⁡(a,b)∣c\gcd(a, b) \mid c. From one solution (x0,y0)(x_0, y_0) (found by the extended Euclidean algorithm), all solutions are x=x0+bdtx = x_0 + \dfrac{b}{d}t, y=y0−adty = y_0 - \dfrac{a}{d}t with d=gcd⁡(a,b)d = \gcd(a, b) and t∈Zt \in \mathbb Z.

Geometrically the solutions are the lattice points on a line, spaced evenly along it. The spacing (b/d,−a/d)(b/d, -a/d) is the smallest integer step along the line, which is why dd appears: with d>1d > 1 the naive step (b,−a)(b, -a) skips solutions. Constraints like "positive solutions" become inequalities in tt — usually leaving finitely many.

Example
Solvable or not?

Does 6x+9y=206x + 9y = 20 have integer solutions? The left side is always a multiple of gcd⁡(6,9)=3\gcd(6, 9) = 3, and 2020 is not: none. What about 6x+9y=216x + 9y = 21? Now 3∣213 \mid 21, and x=2x = 2, y=1y = 1 works (12+9=2112 + 9 = 21). With d=3d = 3, the general solution is x=2+3tx = 2 + 3t, y=1−2ty = 1 - 2t.

Example
Positive solutions
xy5101520253051015(5, 15)(16, 8)(27, 1)
The line 7x + 11y = 200 passes through a lattice point every 11 steps right and 7 down.

Find all positive solutions of 7x+11y=2007x + 11y = 200. First solve 7x+11y=17x + 11y = 1: Euclid gives 7⋅(−3)+11⋅2=17\cdot(-3) + 11\cdot2 = 1. Multiply by 200200: x0=−600x_0 = -600, y0=400y_0 = 400. General: x=−600+11tx = -600 + 11t, y=400−7ty = 400 - 7t. Positivity: 11t>60011t > 600 needs t≥55t \ge 55, and 7t<4007t < 400 needs t≤57t \le 57. So t=55,56,57t = 55, 56, 57 give (5,15),(16,8),(27,1)(5, 15), (16, 8), (27, 1).

Example
Cows and sheep

A farmer spends exactly $1000\$1000 on cows at $80\$80 and sheep at $30\$30, buying at least one of each. In how many ways? 80c+30s=100080c + 30s = 1000, or 8c+3s=1008c + 3s = 100. Mod 33: 8c≡2c≡100≡18c \equiv 2c \equiv 100 \equiv 1, so c≡2(mod3)c \equiv 2 \pmod 3. Try c=2,5,8,11c = 2, 5, 8, 11 (the next, 1414, costs too much): s=28,20,12,4s = 28, 20, 12, 4. Four ways.

Side note
Where it goes wrong

Stepping by (b,−a)(b, -a) when d>1d > 1. For 6x+9y=216x + 9y = 21, starting at (2,1)(2, 1) and stepping by (9,−6)(9, -6) reaches (11,−5)(11, -5) but skips (5,−1)(5, -1): 30−9=2130 - 9 = 21. The true step is (9/3,−6/3)=(3,−2)(9/3, -6/3) = (3, -2).

Try it
Try it: stamps

In how many ways can $1.00\$1.00 be made from 55-cent and 77-cent stamps (order irrelevant)?

Show the answer

5x+7y=1005x + 7y = 100 with x,y≥0x, y \ge 0. Since 5∣1005 \mid 100 and 5∣5x5 \mid 5x, 5∣7y5 \mid 7y, so yy is a multiple of 55: y=0,5,10y = 0, 5, 10 give x=20,13,6x = 20, 13, 6 (y=15y = 15 is too much). 3 ways.

Factoring and Bounding

Concept
Simon's Favorite Factoring Trick

xy+ax+by=cxy + ax + by = c becomes (x+b)(y+a)=c+ab(x + b)(y + a) = c + ab: add the missing constant to complete the product, then list factor pairs. More generally, get one side to factor and the other to be a constant, and the equation reduces to finitely many cases. When nothing factors, bound a variable by size.

The trick is a change of variables that turns a hyperbola into one with axes parallel to the coordinate axes; the integer points on XY=NXY = N are the divisor pairs of NN, of which there are finitely many. For equations without such a factorization, order the variables (a≤b≤ca \le b \le c) and use the smallest one to bound the whole equation.

Example
SFFT
xy51051015(3, 16)(15, 4)
The hyperbola (x − 2)(y − 3) = 13 has asymptotes x = 2, y = 3 and just two positive lattice points.

Solve xy−3x−2y=7xy - 3x - 2y = 7 in positive integers. The product (x−2)(y−3)(x - 2)(y - 3) expands to xy−3x−2y+6xy - 3x - 2y + 6, so add 66 to both sides: (x−2)(y−3)=13(x - 2)(y - 3) = 13. Since x≥1x \ge 1 and y≥1y \ge 1, the factors are at least −1-1 and −2-2, which rules out the negative pairs (−1,−13)(-1, -13) and (−13,−1)(-13, -1). The pairs (1,13)(1, 13) and (13,1)(13, 1) give (x,y)=(3,16)(x, y) = (3, 16) and (15,4)(15, 4).

Example
Unit fractions

Find all positive integers with 1x+1y=16\dfrac1x + \dfrac1y = \dfrac16. Clear denominators: 6y+6x=xy6y + 6x = xy, so xy−6x−6y=0xy - 6x - 6y = 0 and (x−6)(y−6)=36(x - 6)(y - 6) = 36. Could both factors be negative? Then x−6x - 6 and y−6y - 6 would each be at least −5-5, making the product at most 25<3625 < 36: impossible. So both are positive divisors of 3636, and 3636 has 99 of them: 99 ordered solutions, from (7,42)(7, 42) to (42,7)(42, 7) through (12,12)(12, 12).

Example
Bounding by the smallest

Find all positive integers a≤b≤ca \le b \le c with 1a+1b+1c=1\dfrac1a + \dfrac1b + \dfrac1c = 1. The largest term is 1/a1/a, so 1≤3/a1 \le 3/a and a≤3a \le 3; and a≥2a \ge 2. If a=3a = 3, then 1/b+1/c=2/3≤2/b1/b + 1/c = 2/3 \le 2/b forces b=3b = 3, c=3c = 3. If a=2a = 2, then 1/b+1/c=1/2≤2/b1/b + 1/c = 1/2 \le 2/b gives b≤4b \le 4: b=3b = 3 gives c=6c = 6, b=4b = 4 gives c=4c = 4. Answer: (3,3,3)(3, 3, 3), (2,4,4)(2, 4, 4), (2,3,6)(2, 3, 6).

Side note
Where it goes wrong

Forgetting negative factor pairs when the variables may be negative, and forgetting that (a,b)(a, b) and (b,a)(b, a) are different pairs when xx and yy play different roles. In the unit-fraction example the negative pairs had to be ruled out by an argument, not ignored.

Try it
Try it: SFFT

Find all positive integer solutions of xy+x+y=23xy + x + y = 23.

Show the answer

Add 11: (x+1)(y+1)=24(x + 1)(y + 1) = 24, with both factors at least 22. Pairs (2,12),(3,8),(4,6),(6,4),(8,3),(12,2)(2,12),(3,8),(4,6),(6,4),(8,3),(12,2) give (x,y)=(1,11),(2,7),(3,5),(5,3),(7,2),(11,1)(x,y) = \mathbf{(1,11),(2,7),(3,5),(5,3),(7,2),(11,1)} — six solutions.

Congruence Obstructions

Concept
No solution mod mm, no solution at all

If an equation has an integer solution, reducing it gives a solution modulo every mm. So one modulus in which the equation is impossible proves there are no integer solutions. The useful tables: squares are 0,1(mod4)0, 1 \pmod 4 and 0,1,4(mod8)0, 1, 4 \pmod 8; cubes are 0,1,8(mod9)0, 1, 8 \pmod 9.

This is the contrapositive of reduction: integer solution ⇒\Rightarrow solution mod mm. The art is choosing mm so the relevant powers take few values: squares suggest 44 or 88, cubes 77 or 99, powers of 22 suggest 33. A modulus can only ever prove impossibility; it can never prove that a solution exists.

Example
No solutions, mod 44
mod 4y eveny oddx even01x odd12x² + y² mod 4 is never 3
Every parity combination gives 0, 1 or 2, never 3.

Solve x2+y2=2023x^2 + y^2 = 2023. Squares are 0(mod4)0 \pmod 4 for even numbers and 11 for odd ones, so x2+y2≡0,1x^2 + y^2 \equiv 0, 1 or 2(mod4)2 \pmod 4. But 2023=4⋅505+3≡32023 = 4\cdot505 + 3 \equiv 3. No solutions — without trying a single pair.

Example
Factor, then use parity

Solve 2x+1=y22^x + 1 = y^2 in positive integers. Rewrite as 2x=(y−1)(y+1)2^x = (y - 1)(y + 1): both factors are powers of 22, and they differ by 22. The only powers of 22 two apart are 22 and 44, so y−1=2y - 1 = 2, y=3y = 3, x=3x = 3: indeed 8+1=98 + 1 = 9. Unique factorization did the work — a product equal to a power of 22 has only powers of 22 as factors.

Example
Three cubes

Show x3+y3+z3=2020x^3 + y^3 + z^3 = 2020 has no integer solutions. Cubes mod 99: n≡0,±1,±2,±3,±4n \equiv 0, \pm1, \pm2, \pm3, \pm4 give n3≡0,±1,±8,0,±64n^3 \equiv 0, \pm1, \pm8, 0, \pm64, and ±8≡∓1\pm8 \equiv \mp1, 64≡164 \equiv 1: every cube is 00 or ±1\pm1. Three of them sum to something between −3-3 and 33, never ≡4\equiv 4. But 2020≡2+0+2+0=4(mod9)2020 \equiv 2 + 0 + 2 + 0 = 4 \pmod 9. Impossible.

Side note
Where it goes wrong

Taking a passed test as proof of a solution. x2+y2=21x^2 + y^2 = 21 gives 21≡1(mod4)21 \equiv 1 \pmod 4, which the table allows — yet there is no solution (21−0,1,4,9,1621 - 0, 1, 4, 9, 16 are 21,20,17,12,521, 20, 17, 12, 5, none a square). Meanwhile x2+y2=2025x^2 + y^2 = 2025 also passes and does have solutions, such as 272+36227^2 + 36^2. A congruence can only close doors.

Try it
Try it: factorial plus five

Find all positive integers nn for which n!+5n! + 5 is a perfect square.

Show the answer

For n≥3n \ge 3, 3∣n!3 \mid n!, so n!+5≡2(mod3)n! + 5 \equiv 2 \pmod 3; but squares are 00 or 1(mod3)1 \pmod 3. So only n=1,2n = 1, 2 remain, giving 66 and 77, neither a square. There are none.

Why It Works

Let d=gcd⁡(a,b)d = \gcd(a, b) and suppose (x0,y0)(x_0, y_0) and (x,y)(x, y) both solve ax+by=cax + by = c. Subtracting, a(x−x0)=b(y0−y)a(x - x_0) = b(y_0 - y); divide by dd: ad(x−x0)=bd(y0−y)\tfrac ad(x - x_0) = \tfrac bd(y_0 - y). Now ad\tfrac ad and bd\tfrac bd are coprime, so by Euclid's lemma bd\tfrac bd divides x−x0x - x_0: write x−x0=bdtx - x_0 = \tfrac bd t. Substituting back gives y0−y=adty_0 - y = \tfrac ad t. So every solution has the stated form, and every such pair is a solution by direct substitution. Nothing is missed and nothing extra is included.