Pythagorean triplet .

139 Views Asked by At

You are given hypotenuse $h$ of triangle . Can you find out whether integral pythagorean triplet can be formed or not ? e.g given $h = 15$ . You can form triplet as $15,12,9$ because $15^2 = 12^2 + 9^2$ .

1

There are 1 best solutions below

1
On

Every Pythagorean triple is given by Euclid's formula: $$(k(m^2-n^2),\ 2kmn,\ k(m^2+n^2))$$ where $k,m,n$ are positive integers, $m>n$, $m-n$ is odd and $m$ and $n$ are coprime. So, if you are given hypotenuse $h$ you have to check whether it can be expressed in the form $h = k(m^2+n^2)$ subject to given conditions.