TITLE: Finding a Pythagorean triple $a^2 + b^2 = c^2$ with $a+b+c=40$
QUESTION [10 upvotes]: 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?

REPLY [2 votes]: Neat question.  If one were to allow for answers in $\mathbb{Z}$, you can have as many as 18 solutions.
$$\begin{align}
&(65,72,-97) &&(90,56,-106) &&&(140,48, -148) \\
&(240,44,-244) &&(440, 42, -442) &&&(840, 41, -841) \\ 
&(45,200,-205) &&(50,120,-130) &&&(60,80,-100) 
\end{align}$$
$$\begin{align}
&***(8,15,17)*** &&(24,-10, 26) &&&(32,-60,68) \\
&(36,-160,164) &&(38,-360,362) &&&(39,-760,761) \\
&(-120,35,125) &&(-40,30,50) &&&(0,20,20)
\end{align}$$
Solution:
$$\begin{cases} a^2+b^2=c^2 &&&&&&(1)\\a+b+c=40 &&&&&&(2)\end{cases}$$
$$(2) \  \text{for c into} \ (1)\to $$
$$\begin{align}
a^2+b^2&=[40-(a+b)]^2 &&\implies \\
a^2+b^2&=1600-80(a+b)+(a+b)^2 &&\implies \\
0&=1600-80(a+b)+2ab &&\implies \\
0&=ab-40(a+b)+800 &&\implies \\ 
800 &= ab - 40(a+b) + 1600 &&\implies \\
800 = d_1 \cdot d_2&= (a-40)(b-40)&&\implies \\
&\Bigg{\Downarrow} \\
\end{align}$$
$$\begin{cases} a=40+d_1 \\ b=40+d_2  \\ c =-40-(d_1+d_2)\end{cases} $$
The sides of the triangle are now defined parametrically in terms of an arbitrary choice of divisors of $800$. Here, for any choice of a divisor-pair $(d_1,d_2)$, switching the order doesn't produce a new solution, (other times it can), but there is an additional $(-d_1,-d_2)$ solution.  
Since, 
$$\begin{align}
800=2^{\color{red}{5}} \cdot 5^{\color{red}{2}} &\implies 
(\color{red}{5}+1)(\color{red}{2}+1)=18 \ \text{divisors} \\
&\implies 9 \ \text{divisor-pairs} \\
&\implies 18 \ \text{divisor-pairs including negatives}
\end{align}$$
we expect $18$ solutions overall, evaluated above.