Math Core

Module 3.3 · Number Theory

Linear Diophantine equations

A Diophantine equation is an equation where only integer solutions count. The linear ones, ax+by=cax + by = c, show up on the AMC as ticket sales, coin and stamp problems, and "how many ways" questions. You need three skills: decide whether there are any solutions, write down all of them, and count the ones that fit the constraints (usually positive or nonnegative).

When are there solutions?

Whatever integers xx and yy you pick, ax+byax + by is a multiple of g=gcd⁡(a,b)g = \gcd(a, b). So if g∤cg \nmid c there are no solutions. The converse is also true (it follows from the Euclidean algorithm, in the next module): ax+by=cax + by = c has integer solutions exactly when gcd⁡(a,b)\gcd(a, b) divides cc. For example, 6x+15y=406x + 15y = 40 has none, because every value of 6x+15y6x + 15y is a multiple of 33.

All solutions from one

Suppose gcd⁡(a,b)=1\gcd(a, b) = 1 and (x0,y0)(x_0, y_0) is one solution. If (x,y)(x, y) is another, subtracting gives a(x−x0)=−b(y−y0)a(x - x_0) = -b(y - y_0). Since aa and bb share no factor, bb must divide x−x0x - x_0. That forces the following.

General solution

If gcd⁡(a,b)=1\gcd(a, b) = 1 and (x0,y0)(x_0, y_0) is one solution of ax+by=cax + by = c, then every solution is

x=x0+bt,y=y0−at,t an integer.x = x_0 + bt, \qquad y = y_0 - at, \qquad t \text{ an integer}.

Solutions step by bb in xx and by aa in yy (in opposite directions). If gcd⁡(a,b)=g>1\gcd(a, b) = g \gt 1, divide the whole equation by gg first.

To find one solution, use congruences: ax+by=cax + by = c forces by≡c(moda)by \equiv c \pmod a. Solve for yy modulo aa, then compute xx.

Counting solutions with constraints

Once you have the general solution, the constraints x≥0x \ge 0 (or x>0x \gt 0) and y≥0y \ge 0 become two inequalities on tt, and you count the integers in between. Often it's quicker to say "yy must be ≡r(moda)\equiv r \pmod a" and list the values of yy directly.

The Chicken McNugget theorem

Which amounts can you make from aa-cent and bb-cent coins, using nonnegative numbers of each?

Chicken McNugget theorem

If aa and bb are relatively prime positive integers, the largest integer that cannot be written as ax+byax + by with x,y≥0x, y \ge 0 is

ab−a−b,ab - a - b,

and exactly (a−1)(b−1)2\dfrac{(a-1)(b-1)}{2} positive integers cannot be written that way.

Why: every integer nn has exactly one representation n=ax+byn = ax + by with 0≤y≤a−10 \le y \le a - 1. It uses nonnegative coins exactly when that x≥0x \ge 0. The worst case is y=a−1y = a - 1 and x=−1x = -1, which gives n=−a+b(a−1)=ab−a−bn = -a + b(a - 1) = ab - a - b. Every larger nn has x≥0x \ge 0. For the count, nn and ab−a−b−nab - a - b - n can't both be representable (they would add to ab−a−bab - a - b) and one of them always is, so exactly half of 0,1,…,ab−a−b0, 1, \dots, ab - a - b fail.

With three or more coin values there is no formula. List which residues you can reach modulo the smallest coin, and the smallest amount reaching each.

Worked example: Finding every solution

Find all positive integer solutions of 7x+11y=1007x + 11y = 100.

Mod 77: 11y≡10011y \equiv 100, that is 4y≡2(mod7)4y \equiv 2 \pmod 7. Try y=4y = 4: 16≡216 \equiv 2. So y≡4(mod7)y \equiv 4 \pmod 7. With y=4y = 4, 7x=567x = 56 and x=8x = 8.

The general solution is x=8−11tx = 8 - 11t, y=4+7ty = 4 + 7t. For x>0x \gt 0 you need t≤0t \le 0; for y>0y \gt 0 you need t≥0t \ge 0. So t=0t = 0 and the only positive solution is (8,4)(8, 4).

Worked example: Counting nonnegative solutions

How many ordered pairs of nonnegative integers (x,y)(x, y) satisfy 3x+5y=1003x + 5y = 100?

Mod 33: 5y≡1005y \equiv 100, so 2y≡12y \equiv 1 and y≡2(mod3)y \equiv 2 \pmod 3. Also 5y≤1005y \le 100, so y≤20y \le 20. The values y=2,5,8,11,14,17,20y = 2, 5, 8, 11, 14, 17, 20 each give a nonnegative integer xx. There are 77 solutions.

Worked example: Coins that can't make change

Coins come in 66-cent and 1111-cent values. What is the largest amount you can't pay exactly, and how many positive amounts can't be paid?

gcd⁡(6,11)=1\gcd(6, 11) = 1, so the largest impossible amount is 6⋅11−6−11=496 \cdot 11 - 6 - 11 = 49 cents, and the number of impossible positive amounts is 5⋅102=25\dfrac{5 \cdot 10}{2} = 25.

Worked example: A three-variable count

In how many ways can you make 2020 cents from pennies, 22-cent coins and nickels?

You need nonnegative x+2y+5z=20x + 2y + 5z = 20. Fix zz and count solutions of x+2y=20−5zx + 2y = 20 - 5z, which has ⌊20−5z2⌋+1\left\lfloor \dfrac{20 - 5z}{2} \right\rfloor + 1 solutions:

zz20−5z20 - 5zsolutions
0020201111
11151588
22101066
335533
440011

The total is 2929.

Common mistake

Read the constraints carefully. "Positive" means x,y≥1x, y \ge 1; "nonnegative" allows 00. The Chicken McNugget formula is for nonnegative combinations. If both kinds of coin must be used at least once, the amounts shift up by a+ba + b.

Practice

Practice 1

Which of the following equations has no solution in integers xx and yy?

Practice 2

How many ordered pairs of positive integers (x,y)(x, y) satisfy 4x+7y=1504x + 7y = 150?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 3

Using only 77-point and 99-point scoring plays, what is the largest score a team can not reach?

Practice 4

A theater sold adult tickets for $11 each and child tickets for $7 each, taking in exactly $200. At least one of each kind was sold. What is the greatest possible total number of tickets sold?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 5

How many positive integers can not be written in the form 5a+8b5a + 8b with aa and bb nonnegative integers?

Practice 6

Stamps come in 1313-cent and 1717-cent values. In how many ways (counting only how many of each stamp you use) can you make exactly $10.00 of postage?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 7

A snack bar sells boxes of 88, 1212 and 1515 nuggets. How many positive whole numbers of nuggets can not be bought exactly?

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Real contest practice