Diophantine equations
Suppose we have sealed packs of 3 objects and sealed packs of 5 objects. We want exactly 29 objects, and we cannot open a pack. How many packs of each size should we take? A calculation that gives part of a pack does not solve this problem. In this page, we will see how the requirement to use whole numbers changes the way we solve an equation. This page starts from integers and division with remainder; the [[divisibility|divisibility]] and [[congruences|congruences]] pages give more detail on these tools, and the parts used here are explained as we go.
Finding some answers and proving that there are no others are two different jobs. We will find examples and check them in the original equation. We will also ask whether any answers could have been missed, and give a reason for our conclusion.
Why must the answers be whole numbers?
Let be the number of 3-object packs and the number of 5-object packs. The letter is a name for a number we have not chosen yet. If , the first kind contributes objects. If , the second kind contributes objects. Together they give .
The symbol means ‘belongs to’. The braces list the allowed numbers, and the dots mean that the list continues. Here and may be 0, because we may choose none of one kind. They cannot be negative, because we cannot take a negative number of packs. They also cannot be fractions. We call 0, 1, 2, … the nonnegative integers.
Use the two sliders below to change the numbers of packs. A green outline holds 3 dots, and an amber outline holds 5. Each dot is one object. Keep the target 29 fixed and watch how and contribute to the total. Then try and : gives another choice.
Count the packs before we solve the equation
packs, 3 objects in each
packs, 5 objects in each
Now let us separate the equation from this particular story. An integer can also be negative: …, , …. We write for the collection of all integers. For example, and satisfy . This is an integer solution of the equation, but it is not a valid choice of packs. We must state which of these questions we are answering.
An equation whose unknowns must be integers is called a Diophantine equation, after the Greek mathematician Diophantus, who studied such problems. Our linear examples will have no integer solutions or infinitely many; a later nonlinear example will have exactly six. The restriction on the unknowns is the essential point.
Turn a calculation into a point
We do not need to guess both numbers at once. Once is chosen, the total 29 tells us what must be. Subtracting from both sides leaves on the left. Dividing both sides by the nonzero number 5 then gives .
For , this gives . The equality is true: . But 5.8 is not an integer. For , we get , which is an integer. Solving the equation over the real numbers allows both answers; solving it over the integers allows only the second. Here real numbers include whole numbers and fractions, as well as other positions on the number line.
To make this distinction visible, we use two number lines that cross at zero. The horizontal one records , and the vertical one records . The pair (3, 4) means move 3 units to the right from the crossing, then 4 units up. A grey dot is placed wherever both coordinates are integers. These regularly spaced dots form an integer lattice. We are looking for calculated points that land exactly on these dots, not between them.
Calculate a row, then place its point
Grey dots: both coordinates are integers. Green: a calculated solution at a grey dot. Amber: the equation holds, but is not an integer. The purple segment appears after the ten rows.
Each press keeps the earlier points and adds the next whole-number . Nothing advances by itself, so you can inspect every calculation.
| Whole packs? |
|---|
Why does the purple graph form a straight line? If changes by an amount , substituting gives . So a horizontal change of always produces a vertical change of . For , dividing the vertical change by the horizontal change gives . The ratio is fixed. This is exactly a straight line with slope ; the word slope records vertical change divided by horizontal change. The line includes fractional coordinates too. Only its integer-coordinate points answer the integer question.
For nonnegative pack counts, cannot exceed 9: if , the first kind alone contributes at least , already more than 29. Thus checking through 9 really does check every nonnegative possibility in this particular problem. But it does not check every integer solution, because could be negative and could then be larger. We need a proof that reaches beyond this finite picture.
Before searching, can a solution exist?
Change the pack sizes to 6 and 9, and ask for a total of 31. Before trying lots of pairs, notice that both pack sizes are multiples of 3. Any number of either kind still contributes a multiple of 3. Adding them cannot change this fact.
If and are integers, then is an integer. The left side is therefore exactly 3 times an integer. The number 31 is not: dividing it by 3 gives 10 with remainder 1. This proves that has no integer solution, even if negative and are allowed. We did not fail to find a solution; we proved that one cannot exist.
Let us write the same reasoning for positive integer coefficients and and an integer target . A positive integer divides if for some integer ; we write . A common divisor divides both and . The largest positive common divisor is their greatest common divisor, written . It exists here because 1 is a common divisor, while no positive divisor of can exceed the positive number .
If has an integer solution, the last line says times the integer . Therefore is necessary. The word necessary means that a solution cannot exist without this condition. It does not yet mean that the condition guarantees a solution. That converse is our next task.
For 6 and 9, the positive divisors are {1, 2, 3, 6} and {1, 3, 9}; the largest common one is 3. A target of 30 passes the necessary test because . This only tells us to continue. We will now build a solution, rather than assume that passing the test is enough.
How division produces one solution
Our goal is to express the greatest common divisor as an integer plus an integer. If we can do that, multiplying both integers by will produce the target whenever divides . Division with a remainder gives us a way to make this expression.
First see the whole calculation with 3 and 5
Take away one group of 3 from 5; the remainder is 2. Then take away one group of 2 from 3; the remainder is 1. Finally 2 contains two groups of 1 with nothing left. At each stage the next remainder is smaller than the number we divided by.
Watch the remainder become the next measuring group
Each small square represents 1. Compare the row showing the total with the same squares divided into equal green groups and an amber remainder. In the next step, the old group size becomes the new total, and the remainder becomes the new group size.
Next we divide 3 by 2. The remainder 2 is smaller than the group size 3.
The last nonzero remainder is 1. To write it using the original 3 and 5, read the second equation backwards: . The first equation says . Replace the 2 by that expression, then distribute the minus sign.
So is an integer solution of . Check it directly: , and . It is not a pack choice, but we have achieved the current goal of finding one integer solution. Later we will move from one solution to all the others, including (3, 4).
Why does the division process always stop?
For two positive integers and , keep taking away from until the amount left is less than . If , we take away zero groups. Because each subtraction reduces a nonnegative amount by at least 1, only finitely many subtractions are possible. Counting the groups gives a nonnegative integer and a remainder with and .
When is nonzero, repeat with the pair . The second number keeps becoming a strictly smaller positive integer. It cannot decrease forever: starting from , it can pass through at most the positive numbers down to 1. Eventually a remainder is zero. This repeated division is called the Euclidean algorithm.
Why is the final nonzero entry the ?
We must show that replacing by preserves every common divisor. If divides and , write and . From we get , so divides too. Thus any common divisor of and also divides and .
Conversely, if divides and , write and . Then , so divides . We have proved both directions: the common divisors of the two pairs are exactly the same. At the end the pair is . Every positive divisor of also divides 0, because . The greatest of these is itself. Since no replacement changed the common divisors, this is also .
Why can always be written using and ?
At the beginning, and already have the required form. Suppose the two numbers at some stage are and , with integer coefficients. The next remainder is their integer combination . Expand it to see what happens to the coefficients.
The new coefficients and are integers because sums and products of integers remain integers. So the required form is preserved at every step. The final is one of the numbers retained during this process. It may be an original number if the first division is exact, or a later remainder. Both cases have the required form, so there are integers and such that . Reading the divisions backwards computes these coefficients, as we did for 3 and 5. This statement is often called Bézout’s identity; the name comes after the argument, not in place of it.
If divides , then is an integer. The last equation constructs an integer solution . We have now proved sufficiency as well as necessity: for positive integers and , has integer solutions if and only if divides . ‘If and only if’ means that each statement implies the other. It does not promise nonnegative solutions.
For , division gives and . Backwards, . Multiply by 10 because : . Hence is one solution. In contrast, no integer scaling of 3 gives 31, exactly as our necessary-condition argument predicted.
How do we know we have every solution?
Return to and the solution (3, 4). Increasing by 5 adds to the total. Decreasing by 3 removes . The two changes cancel, so (8, 1) is another solution. Reversing the move gives . Repeating a whole number of moves suggests and , where may be any integer, including a negative one or zero.
Substitution proves that every pair we generate works. But could there be another solution that this rule never reaches? To answer that, begin with an arbitrary integer solution , meaning any solution at all, not one selected from our list. Subtract the known equality from its equality .
The symbol names a change: is , not a new multiplication. We need to show that is a multiple of 5. We cannot just cancel a 3 from a divisibility claim without a reason. Use the identity that we derived above. Multiply it by , then use .
The expression in parentheses is an integer, so for some integer . Substitute this into : . Divide by the nonzero number to get . Thus the arbitrary solution must have and . We proved both jobs: every generated pair is a solution, and every integer solution is generated. That is a complete solution.
Repeat the argument with general coefficients
Suppose , and divides . Let be one integer solution; the small zero is only a label for our starting solution. Write and . These are positive integers. They have no common positive divisor larger than 1: if divided both, would divide both and ; for this would give , contradicting the definition of as the greatest common divisor. We say and are coprime.
We divided by to obtain the last line, which is allowed because . Since and are coprime, the Euclidean argument gives integers , with . Multiply by . The term can be replaced by , so both terms then contain .
Therefore for some integer . Substitution into gives . Since , divide by and get . Conversely, these changes always cancel: . We have again proved both directions, so all integer solutions are exactly the following.
This also explains why we may choose a convenient starting solution. From the Euclidean solution for the pack equation, taking gives and . Starting from (3, 4) then labels the same solutions with a shifted parameter. For , so the move is . From , four moves give .
In the next model, the horizontal coordinate is and the vertical coordinate is . Green dots are integer solutions; the amber ring marks the selected one. Choose an equation, then change by a whole step. The dashed right-angle path shows the change in first and the change in second, while the arithmetic verifies that the total stays fixed. Try the target 31 too: the impossibility is arithmetic, not a point hidden outside the drawing.
Move between integer solutions without changing the total
Seven labelled points are shown. They continue in both directions. Horizontal and vertical scales fit this example independently; read the coordinates, not the apparent angle.
One step adds 5 to and subtracts 3 from . The change in the total is .
Both counts are nonnegative, so this point can represent packs.
The displayed comes from these Euclidean divisions; the earlier proof explains why the last nonzero entry is the greatest common divisor.
Return to the packs
The complete integer answer to is . Our packs require and as well. We therefore impose both inequalities on the same parameter , not on two independently chosen numbers.
In the first line we subtracted 3 and divided by positive 5, so the inequality direction did not change. In the second we added to both sides, then divided by positive 3. Combining them gives . Because and , the only integers in this interval are 0 and 1.
| Check total | |||
|---|---|---|---|
| 0 | |||
| 1 |
Thus our two choices are exactly (3, 4) and (8, 1). ‘Exactly’ is justified twice now: we checked all nonnegative values earlier, and we have just restricted a proven complete integer solution. A competition answer should make that completeness visible, rather than stop after listing two successful guesses.
For a reusable form, let mean the smallest integer at least , and let mean the greatest integer at most . These are definitions of rounding upwards and downwards on the number line. For example, because 0 is the first integer to its right, while because 1 is the last integer to its left. With and , the two nonnegative conditions become the following.
If the lower integer bound exceeds the upper one, there is no nonnegative solution, even though integer solutions may exist. For instance, has the integer solution , because . Its full solution is . Nonnegativity requires , hence , and , hence . No integer meets both. This is why | alone cannot solve a counting problem.
When the unknowns multiply each other
So far each unknown has been multiplied only by a fixed number. Such equations are linear. Now consider with and integers. The product makes this a different kind of equation. The previous linear formula does not apply. We need a way to turn the equation into a finite question about integers.
Products suggest factors. Move and to the left by subtracting them from both sides: . The expression nearly matches . We check by multiplying each term, rather than assuming the match: . The missing term is , so add 1 to both sides of our equation.
Let and , so . Subtracting 1 from an integer gives an integer, and conversely any integer gives the integer . Thus this change of names neither loses nor invents integer pairs. We must find every ordered factor pair of 4; ordered means that the first number supplies and the second supplies , so exchanging them can give a different solution.
Neither factor can be zero because their product is 4. Their signs must agree: one positive and one negative would give a negative product. If both are positive, each is at least 1, so neither can exceed 4. Test , 4: the matching values are . The third is not an integer. If both factors are negative, write with , positive. Then , so the negative pairs are precisely the negatives of the three positive pairs.
| (1, 4) | (2, 5) | ||
| (-1, -4) | (0, -3) | ||
| (2, 2) | (3, 3) | ||
| (-2, -2) | (-1, -1) | ||
| (4, 1) | (5, 2) | ||
| (-4, -1) | (-3, 0) |
Select a factor pair below. The display adds 1 to each coordinate and checks both sides of the original equation separately. Because every algebraic step can be reversed and our factor list is complete, these six pairs are all the integer solutions. If the problem had asked for positive and , we would keep only (2, 5), (3, 3) and (5, 2); the other three contain zero or negative coordinates.
In the rectangle, one cell has side length 1 and area 1. The horizontal label and vertical label give absolute values: the size of each number with any minus sign removed. Thus and . Multiplying these side lengths counts the four cells. For a negative pair, this shows the sizes only; we still check the two negative signs in the arithmetic.
Put each factor pair back into the original equation
Each cell is one unit square. The rectangle has columns and rows. Switching a factor pair changes the arrangement while retaining four cells.
Prove impossibility with remainders
Not every equation becomes a useful product. Consider with integer and . Here means . We can test small values, but testing is not the reason there is no solution. Instead, we will show that the left and right sides have incompatible remainders on division by 4. This connects to congruences: saying two integers are congruent modulo 4 means their difference is divisible by 4, equivalently that they leave the same remainder.
Why are those two descriptions equivalent? Write two integers as and , where and are each one of 0, 1, 2, 3. Their difference is . Equal remainders make this divisible by 4. Conversely, if it is divisible by 4, then must be a multiple of 4. But , and the only multiple of 4 in that range is 0. Thus .
Every integer , including a negative one, lies in one block from to for an integer , so with {0, 1, 2, 3}. For a precise choice, gives ; multiply by 4 and subtract to obtain . For example, . Square each of the four forms and keep track of multiples of 4.
Each expansion uses , obtained by multiplying the two brackets. Every parenthesis on the right is an integer. Therefore any integer square has remainder 0 or 1 modulo 4. For two squares, the possible remainder sums are and . None needs another reduction by 4, and none is 3.
The right side of leaves remainder 3. If the two sides were equal integers, their remainders would agree. They cannot, so there is no integer solution. The same calculation rules out any target with remainder 3 modulo 4. The reverse statement is not proved: passing a remainder test is only a necessary condition, just as we carefully distinguished before proving the linear existence theorem.
Try the reasoning on nearby problems
For each question, decide what a complete answer needs before calculating: a proof of impossibility, one solution plus every possible move, or a complete factor list. The worked answers below are available when you want to compare your reasoning. They do not advance automatically.
1. Find every integer solution of , then keep the nonnegative ones.
Division gives and , so . Since , solutions exist. Back-substitution gives , so multiplying by 9 gives . One solution is . The complete move is . Taking three moves gives (0, 3), a more convenient starting point.
The only integer parameters are and 1. They give (0, 3) and (3, 1). Check: , and . The complete-solution theorem proves that the parameter formula includes every integer solution; the inequalities then keep exactly the nonnegative ones.
2. Why does have no integer solution?
Factor the left side: . For integer and , the expression in parentheses is an integer, so the left side is a multiple of 5. But has remainder 2. Equal numbers cannot have these different remainders, so no integer solution exists. It is enough to use the common divisor 5 here; computing the separately is unnecessary for this impossibility proof.
3. Find every integer solution of .
Subtract and from both sides. We want a product, and expanding gives . Add the missing 4 to both sides, obtaining . The complete ordered factor list for 4 was proved above: . Now add 2, rather than 1, to both coordinates.
For any listed factor pair , , we have . With and , the left side is , while . This verifies all six at once. Reversing the factorisation shows that there are no others.
What if a coefficient is zero or negative?
We stated in the main proof so that its divisions and nonnegative inequalities were unambiguous. Do not insert zero into a denominator in that proof. If and , the equation is simply : is allowed only when this quotient is an integer, while may be any integer. If and , similarly must be an integer and is free. If both are zero, the left side is always zero: every integer pair works when , and none works when .
A negative nonzero coefficient can be handled by changing the sign of its unknown. For example, becomes after defining . Every integer gives exactly one integer , and the reverse rule is , so integer solutions are preserved. We already know and ; hence . Check: . If there are nonnegative restrictions, translate them too: means , not .
Why this connects to linear algebra
We can now make the connection without introducing an unexplained new method. In linear algebra, a pair of numbers can be written as a column. We call such a column a vector here. Adding two columns means adding their first entries and adding their second entries. Multiplying a column by a number means multiplying each entry. These operations describe the same coordinate moves we have already used.
For , start at (2, 2). The column describes a move: add 3 to the first coordinate and subtract 2 from the second. The equation checks a pair by multiplying its first entry by 6 and its second by 9, then adding. We can write that operation using a row [6 9], called a one-row matrix. The following multiplication is its definition here.
Before using matrix notation for a sum, let us expand the ordinary arithmetic inside it. Write the two entries of a column as and , and those of another column as and . The small labels 1 and 2 mean first and second positions, not powers. Adding the columns gives entries and . Now multiply the first by 6 and the second by 9.
For subtraction the same expansion gives , which we write as . Thus the compact matrix rules below come from the distributive law we have just used, rather than a new assumption.
The move contributes zero to the total, which is why it can be added to a solution. More generally, if is one column with and is a column with , distributing ordinary multiplication gives . Conversely, if is any other column with , subtract the first equality: . Thus every solution is one particular solution plus a move whose output is zero.
Let us draw that subtraction before giving the collection of moves a name. Keep the starting solution (2, 2) fixed. In step 1 below, choose a point on . In step 2, subtract 2 from its horizontal coordinate and 2 from its vertical coordinate. The same subtraction is applied to every displayed point. Watch the starting solution become the origin, and compare the unchanged coordinate differences.
Subtract the same starting point from every solution
The small amber ring marks the starting point; the larger ring marks the chosen point. Green dashes show the coordinate changes between them. Subtracting (2, 2) moves every point left 2 and down 2; the changes between points stay the same.
At , the selected solution is (5, 0). Its change from (2, 2) is . Press step 2 to see these differences become coordinates.
The set of moves with output zero is called the kernel, or null space, of the matrix. This name records the property that we have just explained. For our row [6 9], write . Then gives after division by 3. Let ; over the real numbers this is always allowed. We get and . Thus every real zero-output move is .
Here means the real numbers. Allowing any real fills the whole straight line; taking gives , a real solution with a fractional first coordinate. Requiring integer coordinates leaves separated points on that line. Why must then be an integer? If and are both integers, because . Their sum is an integer. Conversely, integer makes both coordinates integers. This proves the exact restriction, rather than inferring it from the picture.
There is a trap here. The larger move also contributes zero, since . With a real parameter it describes the same direction. But using only integer multiples of from (2, 2) misses (5, 0): the required change is only one third of that larger move. This is why our integer formula uses , not just . The coprime argument proved that this smaller move reaches every integer solution.
Linear algebra helps explain the shape and the ‘particular solution plus zero-output moves’ structure. Number theory adds the arithmetic question of whether that real shape contains integer points. For example, has the real solution , because . But its left side is , an even integer whenever and are integers, so it has no integer solution. Solving a real linear equation does not settle the integer problem.
Return once more to our original packs. The equation describes a real line, the integer condition selects its lattice points, and the counting condition keeps only points with both coordinates nonnegative. We proved each selection separately. That habit—state the allowed numbers, preserve equivalence when changing an equation, and prove that the final list is complete—is what lets the calculations answer the original question.
