In the 1967 MAA High School Mathematics Contest (Problem #24), students were challenged to solve this algebra problem:
"The number of solution-pairs in positive integers of the equation $3x + 5y = 501$ is:" (A) 33 (B) 34 (C) 35 (D) 100 (E) none of these
An algebraic equation where the solutions must be integers is called a Diophantine equation, named after the Greek mathematician Diophantus of Alexandria (c. 250 AD).
To solve $3x + 5y = 501$ algebraically, solve for $x$:
$$3x = 501 - 5y = 3(167) - 5y$$
$$x = 167 - \frac{5y}{3}$$
For $x$ to be an integer, the term $\frac{5y}{3}$ must be an integer. Since 3 does not divide 5, $y$ must be a multiple of 3:
$$y = 3k \quad (k \in \mathbb{Z})$$
Substituting $y = 3k$ back into the formula gives:
$$x = 167 - 5k$$
Because the problem specifies positive integers ($x > 0$ and $y > 0$):
So $k$ can be any integer from $1$ to $33$. There are exactly 33 positive integer solution pairs!
In geometry, each integer pair $(x, y)$ corresponds to a lattice point lying on the line $y = -\frac{3}{5}x + \frac{501}{5}$. In this lesson, we write code to search for, count, and display these solutions.
solutions = 0 for y = 1, 100 do rem = (501 - 5 * y) % 3 x = (501 - 5 * y) / 3 if rem == 0 and x > 0 then solutions = solutions + 1 end end
Move the mouse over a dotted box for more information.
Lattice points: Points whose coordinates $(x, y)$ are both integers are called lattice points. The equation $3x + 5y = 501$ describes a straight line with slope $-3/5$. Stepping from one solution to the next means decreasing $x$ by 5 and increasing $y$ by 3!
Smallest and largest solutions:
Largest $x$: $k = 1 \implies x = 162, y = 3$
Smallest $x$: $k = 33 \implies x = 2, y = 99$
Now you try. Run the code to see the solutions printed. Notice that $x$ decreases by 5 and $y$ increases by 3 on every consecutive solution!
Type your code here:
See your results here:
The code searches for integer solutions to $3x + 5y = 501$.
Replace ???? with 0 so only positive values of $x$ ($x > 0$) are counted.
When you click Run, notice that each solution $(x, y)$ exactly satisfies $3x + 5y = 501$, and the total count is 33!
Share your code
Show a friend, family member, or teacher what you've done!