Finding a Pythagorean triple $a^2 + b^2 = c^2$ with $a+b+c=40$ Let's say you're asked to find a Pythagorean triple $a^2 + b^2 = c^2$ such that $a + b + c = 40$. The catch is that the question is asked at a job interview, and you weren't expecting questions about Pythagorean triples.

It is trivial to look up the answer. It is also trivial to write a computer program that would find the answer. There is also plenty of material written about the properties of Pythagorean triples and methods for generating them. However, none of this would be of any help during a job interview.

How would you solve this in an interview situation?
Assuming you do have a pen and paper, you could substitute $c = 40 - a - b$ into the first equation to get

$$a^2 + b^2 = (40 - a - b)^2 = a^2 + b^2 + 1600 - 80(a + b) + 2ab.$$

Rewriting this equation, you get

$$a + b - 20 = \frac{ab}{40}.$$

From this it follows that $ab$ has to be a multiple of $40$, i.e., one of them is a multiple of $5$. That narrows it down to only a few options...



If that's still too much brute-force, you could also note that $a + b &gt; 20$ from the above equation, and $a + b &lt; 27$, since $c$ has to be the largest of the three. This leaves only the three pairs

$$\{(5,16),(10,16),(15,8)\}.$$

Looking at the earlier equation, you see the third pair is the right one.
This is a rect triangle with a length of 40.
for example triangle (3,4,5) with a length of 12, you can get the solution: (120/12,160/12,200/12).
the point is that you know some patterns in advanced. (5,12,13) etc...