Problem 9 is sort of easy too! 🙂

The problem statement is as follows:

A Pythagorean triplet is a set of three natural numbers,

abc, 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 productabc.

Knowing a little maths can take you a long way in this problem.

## Mathematical Discussion

(skip this it bores you. The problem can still be solved without it)

Knowing this can cut your run time from 0.291 seconds to 0.001 seconds (as measured by the

library), which is basically **ctime****99.6%** faster!

Basically, Pythagorean Triplets are an expression for possible *integral* values of the sides of a right angled triangle. Armed with this little nugget of knowledge, we can effectively reduce the iterations that we have to go through to find the required triplet.

## General Algorithm

- We know that
*a*+*b*+*c*= 1000. - Therefore,
*m*^{2}–*n*^{2}+ 2*mn*+*m*^{2}+*n*^{2}= 1000.**So, 2***m*^{2}+ 2*mn*= 1000. - We now attempt to get the answer by applying brute force on the above expression, rather than plugging in all possible values of
*a, b***and***c*. - I believe that the brute force method merits no discussion. It has been included in the source, for comparison with the above method.