You are on the Home/Other Tutorials/Project Euler/Problem 9 page
Web This Site

Project Euler - Problem 9

More about Project Euler.

Problem description

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,

a2 + b2 = c2

For example, 32 + 42 = 9 + 16 = 25 = 52).

There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.


There are three variables and two equations.  We can reduce this to two variables and 1 equation.  After that we will have to switch to a numerical approach with the added constraint that the results be integers greater than 0.

Start with

a2+b2=c2 - (1) and

a+b+c=1000 (2)

(2) gives c=1000-(a+b)

Substituting this in (1) gives

a2+b2=[1000-(a+b)]2 -- (3)

Simplifying (3) yields

2000*(a+b) - 2*a*b = 106

Designate two cells in some worksheet as representing a and b.  I chose G2 and G3.  Then, in some other cell enter the formula =2000*(G2+G3)-2*G2*G3-10^6.  Create a Solver model that specifies the cell with the formula should have a value of zero and that the variables be integer values greater than zero.  The Solver solution will be the answer.