**Problem link:** http://projecteuler.net/problem=9

**Problem Statement:**

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

.

For example, .

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

Find the product abc.

**Solution Idea:**

We have 3 variables a,b,c. So, We need at least 3 equations to solve them in constant time. But, we are given 2 equations: and . So, we combine these 2 equations and can get rid of c, , which will simplify to . Now we can iterate through all possible values of a and find the solution in linear time.

**Solution Gist:**

### Like this:

Like Loading...

*Related*

Tagged: easy, equation, java, math, overflow, pythagorean

AlumashkaNovember 28, 2013 at 1:28 amHowever, with limitation “a + b + c = 1000” even O(N^2) solution would work less than a second.

It would be interesting extend the problem for far greater numbers…

Faisal R.November 28, 2013 at 6:54 amyes , for sure. ๐

Alumashka at CodeAbbeyNovember 30, 2013 at 5:28 amHello, Faisal!

I tell about this task and your explanations to my friend and asked him, whether he can create an improved version of the problem at his web-site. He agreed to try.

See, here it is:

http://codeabbey.com/index/task_view/pythagorean-triples

The numbers there would be greater, over million, so that solution could be found only by your method, not by simply iterating over a and b… ๐

Wouldn’t you mind mentioning you as a person who gives idea? If so, please check if your name is spelled correctly. Thanks a lot once more!

Faisal R.December 1, 2013 at 9:20 pmI am honored, thank you ๐

atiqSeptember 30, 2014 at 8:42 pmThank you Faisal…for very clean approach.