Home Project Euler Teaching Projects Gallery

Problem 9: Special Pythagorean Triplets

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, $$ a^2 + b^2 = c^2 $$

For example, \(3^2 + 4^2 = 9 + 16 = 25\)

There exists exactly one Pythagorean triplet for which a + b + c = 1000.

Find the product abc.


Algorthim:

We can subsitute the value of c as: $$ c = 1000 - a - b $$

Then iterate through all possible values until we see that a, b, c form a Pythagorean triplet

Code:

Result:

Answer: 31875000
Runtime: 668 ms