If I am given two natural numbers, is there a way to determine if they could be the legs of a Pythagorean triple (right triangle with all sides having integer lengths)?
I know one can simply check if $a^2 + b^2$ is a perfect square (where $a$ and $b$ are the legs), but for my purposes this is much too inefficient (ie, computationally intensive).
Are there any methods that would eliminate some candidates, assuming the pair is randomly selected from a given range?
This method is almost certainly more trouble than checking whether $a^2+b^2$ is a square, but it does arrive at the answer without calculating or directly considering $c$, the hypotenuse. It is based on the fact that for any Pythagorean triangle, $a=u^2-v^2,\ b=2uv,\ c=u^2+v^2$ where one of $u,v$ is odd and the other is even.
Let's assume $\gcd (a,b)=d$. Find $r=\frac{a}{d}$ and $s=\frac{b}{d}$. If $a,b$ are legs of a Pythagorean triangle, then $r,s$ are legs of a primitive Pythagorean triangle. We know that one of the legs of a primitive Pythagorean triangle must be odd, and the other even.
WLOG, let $r$ be odd and $s$ be even and divisible by $4$. Now, find all divisors $m_i,n_j$ of $s$ such that $m_i$ are odd and $n_j$ are even, and pair them such that $m_i\cdot n_i=s$.
Now for each pair calculate $(m_i+\frac{n_i}{2})(|m_i-\frac{n_i}{2}|)$. If it so happens that for any pair $(m_i+\frac{n_i}{2})(|m_i-\frac{n_i}{2}|)=r$, then $r,s$ are the legs of a primitive Pythagorean triangle, and $a,b$ are the legs of a Pythagorean triangle.
Like I said, more trouble than the straight forward check on the sum of squares.