A Pythagorean triplet is a set of three natural numbers, $a \lt b \lt c$, for which, $$a^2 + b^2 = c^2.$$
For example, $3^2 + 4^2 = 9 + 16 = 25 = 5^2$.
There exists exactly one Pythagorean triplet for which $a + b + c = 1000$.
Find the product $abc$.
To find three natural numbers $a$, $b$, and $c$ such that $a^2 + b^2 = c^2$ and $a + b + c = 1000$, we can use the relationship $c = 1000 - a - b$ to eliminate one variable and solve in terms of $a$ and $b$.
Substituting $c = 1000 - a - b$ into $a^2 + b^2 = c^2$ gives:
$$a^2 + b^2 = (1000 - a - b)^2$$Expanding and simplifying leads to:
$$a^2 + b^2 = 1000^2 + a^2 + b^2 - 2000a - 2000b + 2ab$$Canceling terms and rearranging for $b$ gives:
$$b = \frac{1000(1000 - 2a)}{2(1000 - a)}$$We can now iterate possible values of $a$ and check whether $b$ is an integer.
In terms of python:
for a in range(1, 1000 // 3):
b = (1000 * (1000 - 2 * a)) / (2 * (1000 - a))
if b.is_integer():
b = int(b)
c = 1000 - a - b
print(a * b * c)
break
Explained line by line:
a from $1$ to $333$ (since a must be less than b and c, and a + b + c = $1000$).a, we calculate b using the derived formula.b is an integer using the is_integer() method.b is an integer, we convert it to an integer type and calculate c as $1000 - a - b$.a * b * c and break out of the loop since we only need one triplet.Running the above code leads to an answer of $31875000$.