Given a number say $x$, how to check if it can become hypotenuse of right angle triangle and other sides must be integer

For example:

$5$ it can be hypotenuse as its other sides $3$ & $4$ are integers.

$13$ it can also hypotenuse as its other sides $12$ & $5$ are integers.

$12$ can't be hypotenuse because other two sides can't be integers.


An integer number $N>0$ can be the hypothenuse of a right angled triangle with integer side lengths if and only if it has a prime factor $p \equiv 1 (4)$ (i.e. $p$ is of the form $4k+1$ with integer $k$).

The proof outline is as follows:

  • If $N^2 = a^2+b^2$ then $(kN)^2 = (ka)^2+(kb)^2$.
  • Any prime $p \equiv 1 (4)$ can be represented as $x^2+y^2$ with positive integers $x,y$ (Fermat's theorem on sums of two squares). And then $p^2 = (x^2+y^2)^2 = (x^2-y^2)^2 + (2xy)^2$
  • All other numbers only have the trivial representation $N^2 = N^2+0^2$ (see e.g. here), which does not form a triangle.
  • $\begingroup$ Thank You so much. Simple, Consise and to the point. $\endgroup$ – DollarAkshay Oct 7 '15 at 18:32

It is known that any primitive pythagorean triple $a^2 + b^2 = c^2$ is on the form $$ (a, b, c) = (2uv, u^2 - v^2, u^2 + v^2) $$for some natural numbers $u>v$, so you basically have to check whether your hypotenuse can be written as the sum of two squares. To confirm your examples, $5 = 4 + 1$, and $13 = 9 + 4$, while $12$ is not the sum of two squares (you can't add your way to $12$ by using only two numbers from $\{1, 4, 9\}$).

If course, it's possible that your number could be the hypotenuse in some non-primitive triple. This happens if it has a divisor that can be written as the sum of two squares. For instance, if at least one of its prime factors are congruent to $1$ modulo $4$.

  • 2
    $\begingroup$ Your interesting observation is false: $15$ can't be written as the sum of two squares, but $225=12^2+9^2$ can. (It's true with "only if" instead of "if and only if".) $\endgroup$ – TonyK Oct 2 '15 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.