Skip to content

← Math Further 9–12

Can You Buy 100 Birds with 100 Coins?

Topic 6 · Grades 9–12 · Diophantine equations

What this builds on from class
  • Grade 7: Whole Number (HCF by the division method)
  • Grade 9: Linear Equation (simultaneous equations)
  • Grade 10: Sequences
In this unit 11 sections
  1. Find every answer
  2. Why the answers march in step
  3. A line through the grid
  4. When is there any answer at all?
  5. Euclid’s algorithm, run backwards
  6. The pulverizer
  7. Amounts you can never pay
  8. When whole numbers make it hard
  9. Where this is used
  10. Questions
  11. Where to go next

About 1,500 years ago, in China, a book of arithmetic ended with a puzzle that has traveled the world ever since. Picture it at a weekly haat bazaar: a poultry seller with a basket of birds, and you with exactly 100 coins in your pocket.

  • A rooster costs 5 coins.
  • A hen costs 3 coins.
  • Chicks are cheap: 3 chicks for 1 coin.

You must come home with exactly 100 birds, and spend exactly 100 coins: no change, no half a bird, no third of a coin left over. How many roosters, hens and chicks do you buy?

Try it

Buy 100 birds with 100 coins

Choose the roosters and the hens with the sliders; the chicks are the rest of the 100 birds. The two bars are drawn to the same scale, so when you have spent exactly 100 coins, both bars end on the line. Every answer you find goes on your list.

2roosters5 coins each20hens3 coins each78chicks3 for 1 coinBirds: 2 + 20 + 78 = 100Coins: 5×2 + 3×20 + 78÷3 = 96100

That is more than 100 roosters and hens already. Take some away.

The chicks can’t be paid for exactly: they come three for a coin, and this many chicks isn’t a multiple of 3.

100 birds, but more than 100 coins. Try again.

100 birds, but less than 100 coins: some money is left over. Try again.

100 birds for exactly 100 coins: both bars end on the line. Is there another answer?

100 birds for exactly 100 coins. That is every answer there is: the rest of this page shows why.

Your answers (roosters, hens, chicks): 0

  1. —
  2. —
  3. —
  4. —

Rooster and hen: Steven Traver, CC0, via PhyloPic; chick: Pearson Scott Foresman, public domain, via Wikimedia Commons

Guess first. How many different ways are there to buy the birds?

Pick an answer to see why.

Find every answer

Play with the market before reading on. Try these, in order.

  • a.Find one answer by any means. (A hint if you are stuck: try 4 roosters.)
  • b.Find an answer with no roosters.
  • c.Try every number of roosters from 0 to 12. Which numbers of roosters ever give an answer?
  • d.Put your answers in a table, roosters going up. What happens to the hens each time? To the chicks?

Someone says: “16 roosters, −3 hens and 87 chicks is a fifth answer.” What is true?

Pick an answer to see why.

Why the answers march in step

The market gives you two facts and asks for three numbers. Call them r roosters, h hens and c chicks:

r+h+c=100(birds) r + h + c = 100 \qquad\text{(birds)}
5r+3h+c3=100(coins) 5r + 3h + \tfrac{c}{3} = 100 \qquad\text{(coins)}

You met two equations in two unknowns in Grades 8 and 9, and they usually have just one answer. With three unknowns there is room to spare, so we get rid of the chicks. Multiply the coins equation by 3, so that every term is a whole number, then take away the birds equation:

15r+9h+c=300 15r + 9h + c = 300
(15r+9h+c)−(r+h+c)=300−100 (15r + 9h + c) - (r + h + c) = 300 - 100
14r+8h=200,so7r+4h=100. 14r + 8h = 200, \quad\text{so}\quad 7r + 4h = 100.

One equation in two unknowns, roosters and hens. With any numbers allowed, it has an endless line of answers: choose r, then h = (100 − 7r)/4. The puzzle’s extra rule is what makes it a puzzle: only whole numbers.

Now look at 7r + 4h = 100 with whole numbers in mind. 4h is a multiple of 4, and so is 100. So 7r must be a multiple of 4 too. 7 and 4 have no common factor, so the 4 has to come from r itself: the roosters must be a multiple of 4. Write r = 4t for a whole number t. Then

28t+4h=100,h=25−7t,c=100−r−h=75+3t. 28t + 4h = 100, \quad h = 25 - 7t, \quad c = 100 - r - h = 75 + 3t.

There is the swap, out of the algebra: each step of t adds 4 roosters, takes 7 hens and adds 3 chicks. The hens can’t go below 0, so 25 − 7t ≥ 0 and t is 0, 1, 2 or 3. Exactly four answers, and a proof that there are no more. And the chicks, 75 + 3t, always come out a multiple of 3, as the price “3 for 1 coin” needs.

An equation where only whole-number answers count is called a Diophantine equation, after Diophantus of Alexandria, a Greek mathematician of about 250 CE (see the story below). The simplest kind, two unknowns with whole-number coefficients,

ax+by=c, ax + by = c,

is a linear Diophantine equation. The Hundred Fowls came down to one: 7r + 4h = 100.

A line through the grid

Draw 7x + 4y = 100 on squared paper. It is a straight line, from (0, 25) on the y-axis to (1427,0) (14\tfrac{2}{7}, 0) on the x-axis. Most of the points on it have fractions in them. The whole-number answers are the points where the line passes exactly through a corner of the squares, a lattice point.

Try it

Whole-number points on a line

The line ax + by = c where x and y are 0 or more, with its whole-number points ringed. It opens on the Hundred Fowls, 7x + 4y = 100. Change a, b and c, and watch the ringed points.

5105101520250xy7x + 4y = 100
HCF of a and b
1
Whole-number points
4

No whole-number points anywhere on this line: whole numbers of a and b always make a multiple of their HCF, and c isn’t one.

c is a multiple of the HCF, so the line does pass through whole-number points, but not here: in every one of them, x or y is negative.

Just one point here. The next ones along the line have x or y negative.

The purple arrow is one step: from each point to the next is the same number of squares across and the same number down.

Try these with the widget.

  • a.Keep a = 7, b = 4 and move c. Are the whole-number points always evenly spaced?
  • b.Set a = 6, b = 9. Find a value of c with no whole-number points at all, and one with several. What do the values with points have in common?
  • c.Set a = 3, b = 5, c = 7. Why are there no points here, though the widget says the line does pass through some?

Why evenly spaced? Suppose (x₁, y₁) and (x₂, y₂) are both on 7x + 4y = 100. Take one equation from the other:

7(x2−x1)+4(y2−y1)=0,so7(x2−x1)=−4(y2−y1). 7(x_2 - x_1) + 4(y_2 - y_1) = 0, \quad\text{so}\quad 7(x_2 - x_1) = -4(y_2 - y_1).

The left side is a multiple of 7, so the right side is too; 4 has no factor 7, so y₂ − y₁ must be a multiple of 7. In the same way x₂ − x₁ is a multiple of 4. So two whole-number points are always a whole number of steps of 4 across and 7 down apart, and that step itself always works. That is the pattern of the market, seen as a picture.

When a and b share a factor, divide it out first. Write g for the highest common factor of a and b, their HCF (also called the greatest common divisor, gcd). Then the step is b/g across and a/g down: on 6x + 9y = 99, g = 3, and each step is 3 across and 2 down.

When is there any answer at all?

The widget’s 6x + 9y = 100 has no whole-number points anywhere, not even with negative numbers. The reason takes one line: whatever whole numbers x and y are, 6x + 9y = 3(2x + 3y) is a multiple of 3, and 100 isn’t. The same argument works for any equation.

The first part we have proved. The second needs more: when g divides c, how do we know there is even one solution, and how do we find it? For the Hundred Fowls a little trying was enough. For 17x + 23y = 1{,}000 trying is slow, and for the numbers a computer works with, hundreds of digits long, it is hopeless. The next section is the method, and it is one you already know half of.

Euclid’s algorithm, run backwards

In Grade 7 you found the HCF by the division method: divide the bigger number by the smaller, then the smaller by the remainder, and so on; the last remainder that isn’t 0 is the HCF. That method is more than 2,000 years old, and it has a name: Euclid’s algorithm, from Euclid’s Elements (about 300 BCE), though Euclid probably collected it from mathematicians before him. For 7 and 4:

7=1×4+3 7 = 1 \times 4 + 3
4=1×3+1 4 = 1 \times 3 + 1
3=3×1+0 3 = 3 \times 1 + 0

The HCF is 1. Now the trick: every remainder can be written as some 7s and some 4s. Read the lines upwards, writing each remainder from the line it came from:

3=7−4 3 = 7 - 4
1=4−3=4−(7−4)=2×4−1×7 1 = 4 - 3 = 4 - (7 - 4) = 2 \times 4 - 1 \times 7

So 7 × (−1) + 4 × 2 = 1: one solution of 7x + 4y = 1. This is Euclid’s algorithm run backwards (often called the extended Euclidean algorithm). It always works, because each remainder is the number before it minus some of the one before that; if those two are made of 7s and 4s, so is the remainder. The last remainder that isn’t 0 is the HCF, so the HCF itself is made of 7s and 4s.

The pulverizer

The Hundred Fowls traveled too. Mahavira’s Ganita-sara-sangraha (850) asks for 100 birds of four kinds, pigeons, sarasa cranes, swans and peacocks, for 100 coins; Alcuin of York (about 735–804) set seven puzzles like it in Europe; and Abu Kamil, in Egypt around 900, wrote a whole Book of Birds on them.

Amounts you can never pay

Now turn the question round. Imagine a shop where the only coins are Rs 3 and Rs 5 (a made-up puzzle). Which amounts can be paid exactly? That asks for whole numbers x, y ≥ 0 with 3x + 5y = n: the same kind of equation, with n changing.

Rs 1, 2 and 4 can’t be paid; Rs 3, 5 and 6 can. Rs 7 can’t: 7 − 5 = 2 and 7 − 3 − 3 = 1 aren’t payable. Rs 8 = 3 + 5, 9 = 3 + 3 + 3, 10 = 5 + 5. And once you can pay 8, 9 and 10, you can pay 11, 12, 13 by adding a Rs 3 coin to each, and so on for ever. So 7 is the largest amount you can’t pay, and there are exactly 4 amounts you can’t: 1, 2, 4 and 7.

Try it

Which amounts can you pay?

Every amount from 0 up, in rows: a step to the right adds one small coin. Shaded amounts can be paid exactly. Try each pair of coins.

Each step right adds Rs 3 →03691215182124014710131619222512581114172023262
Amounts you can’t pay
4
Largest you can’t pay
7
ab − a − b
15 − 3 − 5 = 7

Each row starts being payable at a multiple of 5 (0, 10, 5) and stays payable. The last row starts at 10, so 10 − 3 = 7 is the largest amount you can’t pay.

The rows explain it. Every amount in a row leaves the same remainder when divided by the small coin a. Once a row has one payable amount, every amount to its right is payable too: add one more a-coin each step. So each row has a first payable amount, and that first one is always made of b-coins only (any a-coins in it could be taken away, giving a smaller payable amount in the same row). The first payable amounts are therefore

0, b, 2b, …, (a−1)b, 0,\ b,\ 2b,\ \ldots,\ (a - 1)b,

and they all fall in different rows (if two of them left the same remainder, their difference, a multiple of b smaller than ab, would be a multiple of a too, which can’t happen when a and b share no factor). The last row to start does so at (a − 1)b. The amount just before it in that row, (a − 1)b − a, can’t be paid, and every amount bigger than it can (every other row has already started). So:

Why exactly half of the amounts from 0 to ab − a − b? There is a neat pairing. Call N = ab − a − b, and pair each amount n with N − n: with Rs 3 and Rs 5, N = 7, and the pairs are 0 and 7, 1 and 6, 2 and 5, 3 and 4. In every pair, exactly one can be paid. They can’t both be payable, because then their sum, N, would be payable too. And if n can’t be paid, N − n can: Euclid’s algorithm run backwards gives whole numbers with n = ax + by, and stepping along the line, b at a time in x, brings x to between 0 and b − 1. Then y must be negative, since n isn’t payable, and N − n = a(b − 1 − x) + b(−1 − y), where both brackets are 0 or more. There are N + 1 = (a − 1)(b − 1) amounts from 0 to N, so half of them can’t be paid.

James Joseph Sylvester published the formula ab − a − b in 1882, and he also showed that (a − 1)(b − 1)/2 amounts can’t be paid. The question for three or more coins, the coin problem (or Frobenius problem), has no formula like it; with boxes of 6, 9 and 20 nuggets, the largest number you can’t buy is 43.

When whole numbers make it hard

So far the unknowns stood alone, never squared. Square them, and whole-number questions change character.

  • x2+y2=3 x^2 + y^2 = 3 has no whole-number solutions. Squares of whole numbers are 0, 1, 4, 9, …, and no two of them add to 3. (Looking at remainders on dividing by 4 shows more: a square leaves 0 or 1, so a sum of two squares never leaves 3; 3, 7, 11, 15, … are never sums of two squares.)
  • x2+y2=z2 x^2 + y^2 = z^2 has infinitely many: 3, 4, 5; 5, 12, 13; 20, 21, 29. Finding them all is topic 7.
  • x2−2y2=1 x^2 - 2y^2 = 1 has infinitely many too, 3 and 2, 17 and 12, 99 and 70, 577 and 408, but they grow fast and are hard to find by trying; Bhaskara II’s method for such equations is topic 36.

Which equation has infinitely many solutions in whole numbers?

Pick an answer to see why.

Where this is used

  • Astronomy, long ago: Indian astronomers’ kuttaka found the days since the start of a yuga from a planet’s position (the fact above).
  • Coins, stamps and packs: which amounts or quantities can be made from fixed sizes is the coin problem, answered by ab − a − b for two sizes.

Questions

★ Rooster 5 coins, hen 3 coins, and now 4 chicks for 1 coin; 100 birds for 100 coins. How many answers?

Pick an answer to see why.

a.★

A post office (in a puzzle) sells only Rs 5 and Rs 8 stamps. In how many ways can you put exactly Rs 100 of stamps on a parcel? What is the largest amount you can’t make exactly?

Hint
Answer
b.★★

A puzzle with made-up prices. A stationery shop in Bhaktapur sells notebooks at Rs 50, pens at Rs 15, and erasers at 2 for Rs 5. A school buys exactly 100 items for exactly Rs 1,000, with at least one of each. How many of each could it buy? Find every way.

Hint
Answer

★★ Which of these has no whole-number solutions at all, even with negative numbers?

Pick an answer to see why.

c.★★★

Find every solution of 17x + 23y = 1{,}000 in positive whole numbers.

Hint
Answer
d.★★

Zhang’s prices again, with 200 birds and 200 coins, had 8 answers (the try above). Without working them out, how many answers would 300 birds for 300 coins have? Check by working.

Answer
e.★★★
  • a.Prove that if ax + by = c has a solution in whole numbers, the HCF of a and b divides c.
  • b.With Rs 2 and Rs 9 coins, list every amount you can’t pay. Check your list against ab − a − b and (a − 1)(b − 1)/2.
Answer
f.★★★

In the Hundred Fowls, why did the chicks always come out a multiple of 3, though we never asked for it after the elimination?

Answer

Where to go next

Where these facts come from
  • The Hundred Fowls problem in the Zhang Qiujian suanjing (written between 468 and 486), its prices and Zhang’s three answers, no reasons given for the method; the book’s three chapters: MacTutor, “Zhang Qiujian”, read October 2026.
  • The four answers including (0, 25, 75), the name given by Louis van Hee, Mahavira’s four kinds of bird, Alcuin’s seven similar problems, Abu Kamil (850–930): Wikipedia, “Hundred Fowls Problem”, read October 2026. Abu Kamil’s Book of Birds as a treatise on these problems: search results pointing to ProofWiki’s note on the Kitāb al-ṭair and Eva Caianiello’s history of the problem, read October 2026 (not opened in full).
  • Aryabhata finished the Aryabhatiya in 499 at 23; kuttaka means “to pulverize”; used for whole-number solutions and the periods of the planets: MacTutor, “Aryabhata I”, read October 2026.
  • Verses 32–33 of the Ganitapada, Bhaskara I (about 600–680) naming and explaining the kuttaka, its likeness to the extended Euclidean algorithm, the Laghubhaskariya’s yuga of 1,577,917,500 days and Saturn’s 146,564 turns, the ahargana: Wikipedia, “Kuṭṭaka”, read October 2026 (it cites Datta and Singh, History of Hindu Mathematics, and Shukla’s translation of the Laghubhaskariya).
  • Brahmagupta’s Brahmasphutasiddhanta (628) and his methods for indeterminate equations: MacTutor, “Brahmagupta”, read October 2026.
  • Bhaskara II (1114–1185), the Ujjain observatory, the Lilavati’s chapter 12 problem 221y + 65 = 195x with the answers (6, 5), (23, 20), (40, 35), and the Bijaganita’s horses problem with its smallest answer: MacTutor, “Bhaskara II”, read October 2026. The Lilavati problem is retold in our own words.
  • Diophantus (fl. about 250 CE, Alexandria), the Arithmetica’s thirteen books, six in Greek and four in Arabic, his rational solutions, Fermat’s margin: Wikipedia, “Diophantus”, read October 2026.
  • Fermat’s note (about 1637), Wiles’s 1993 announcement, the gap, Taylor, the May 1995 Annals of Mathematics: Wikipedia, “Fermat’s Last Theorem”, read October 2026.
  • Hilbert’s tenth problem (1900) and its negative answer, completed by Matiyasevich in 1970 after Davis, Putnam and Robinson: Wikipedia, “Hilbert’s tenth problem”, read October 2026.
  • Sylvester’s ab − a − b (1882, American Journal of Mathematics; his 1884 Educational Times question is sometimes cited instead) and the count (a − 1)(b − 1)/2; the 6, 9, 20 nuggets and 43: Wikipedia, “Coin problem”, read October 2026.
  • The extended Euclidean algorithm computes modular inverses, “an essential step in the derivation of key-pairs in the RSA public-key encryption method”: Wikipedia, “Extended Euclidean algorithm”, read October 2026; RSA’s example with 61, 53, 780, e = 17, d = 413: Wikipedia, “RSA cryptosystem”, read October 2026.
  • Every count and answer on this page (the four fowl answers, the lattice points, the 200- and 300-bird markets, the coin rows, Sylvester’s numbers, the stamps, the stationery puzzle, 17x + 23y = 1{,}000, Bhaskara’s multiplier, d = 413) was checked by exhaustive search in a script.