The largest integer that cannot be made from fives and eights

Original publication: Updated:

What does the problem mean?

Problem. Find the largest integer that cannot be written as

5x+8y,x,y∈Z≥0.5x+8y,\qquad x,y\in\mathbb Z_{\ge0}.

For example, 18=5+5+818=5+5+8 is representable, whereas 1717 is not. Repetition is allowed, and either count may be zero. The nonnegativity condition is essential: negative numbers of coins or summands are not permitted.

The answer is 27\boxed{27}. We will prove both that 2727 is impossible and that every larger integer is possible.

An elementary method: use five columns

Arrange the positive integers in five columns, so moving down a column adds five.

The integers arranged in five columns, with numbers in the same column differing by five.

Once a number in a column is representable, every number below it is representable by adding another five. The multiples of eight give a starting point in each residue class modulo five:

0,8,16,24,32.0,\quad8,\quad16,\quad24,\quad32.

Their residues are 0,3,1,4,20,3,1,4,2, so they cover all five columns. These are the smallest representable numbers in their respective columns: using five changes no residue, and the least nonnegative count of eights for each residue is one of 0,1,2,3,40,1,2,3,4.

The last unrepresentable numbers before those starting points are, by residue class 0,1,2,3,40,1,2,3,4,

−5,11,27,3,19.-5,\quad11,\quad27,\quad3,\quad19.

The negative entry simply means every nonnegative multiple of five is already representable. The largest nonnegative obstruction is 2727.

Representable starting points circled in the five-column table, with all subsequent entries in their columns eliminated; 27 is highlighted as the largest remaining number.

A short alternative using five consecutive values

The five integers immediately after 2727 are all representable:

28=4⋅5+8,29=5+3⋅8,30=6⋅5,31=3⋅5+2⋅8,32=4⋅8.\begin{aligned} 28&=4\cdot5+8,&29&=5+3\cdot8,\\ 30&=6\cdot5,&31&=3\cdot5+2\cdot8,\\ 32&=4\cdot8. \end{aligned}

Adding any number of fives proves that every integer at least 2828 is representable.

For 2727, reduction modulo five requires 3y≡2(mod5)3y\equiv2\pmod5, or y≡4(mod5)y\equiv4\pmod5. A nonnegative such yy is at least four, making 8y≥32>278y\ge32>27. Thus 2727 is impossible, completing the proof.

The Diophantine viewpoint

Without the restrictions x,y≥0x,y\ge0, every integer mm can be written as 5x+8y5x+8y, because 5(−3)+8(2)=15(-3)+8(2)=1. One solution for mm is (−3m,2m)(-3m,2m), and every integer solution is

(x,y)=(−3m+8k, 2m−5k),k∈Z.(x,y)=(-3m+8k,\ 2m-5k),\qquad k\in\mathbb Z.

The problem asks whether the integer kk can be chosen so that both coordinates are nonnegative. This is a bounded-feasibility question, not merely whether a linear integer equation has a solution.

The general parameterization is explained in Diophantine equations.

The general two-denomination formula

Let a,b>1a,b>1 be coprime positive integers. The largest integer not representable as ax+byax+by with nonnegative integers x,yx,y is

ab−a−b.\boxed{ab-a-b.}

Here is a proof, so the formula need not be memorized without its conditions.

The proposed largest obstruction is impossible

Set N=ab−a−bN=ab-a-b. If N=ax+byN=ax+by with x,y≥0x,y\ge0, then modulo aa,

by≡−b(moda).by\equiv-b\pmod a.

Since a,ba,b are coprime, y≡−1(moda)y\equiv-1\pmod a, so y≥a−1y\ge a-1. But then

by≥b(a−1)=ab−b>N,by\ge b(a-1)=ab-b>N,

contradicting ax+by=Nax+by=N with ax≥0ax\ge0.

Every larger integer is possible

Take m>Nm>N. The residues of 0,b,2b,…,(a−1)b0,b,2b,\ldots,(a-1)b modulo aa are all distinct, by coprimality. Choose y∈{0,1,…,a−1}y\in\{0,1,\ldots,a-1\} with by≡m(moda)by\equiv m\pmod a. Then x=(m−by)/ax=(m-by)/a is an integer, and

m−by>N−b(a−1)=−a.m-by>N-b(a-1)=-a.

Thus x>−1x>-1, and since xx is an integer, x≥0x\ge0. This constructs a valid representation of every m>Nm>N.

For a=5,b=8a=5,b=8, the formula gives 40−5−8=2740-5-8=27. If the denominations are not coprime, infinitely many integers fail divisibility and there is no largest obstruction. If one denomination is one, every nonnegative integer is representable. Those cases must be separated from the theorem.

Related articles

About the author

Koki Saito

Physician and graduate of the University of Tokyo Faculty of Medicine. Drawing on his entrance-exam experience, he explains how to choose mathematical methods and construct complete solutions.

Full profile →

Have a question or spotted an error? Contact us.