Criterion for being the length of a hypotenuse

number theorypythagorean triples

I'm wondering if the criterion I give below can be simplified. Its goal is to see whether some integer $n\geq 1$ is the length of the hypotenuse of some right-angled triangle with integer side lengths. In other words, given $n\geq 1$, it helps to decide whether there are integers $a,b\geq 1$ for which $a^2+b^2=n^2$.

Here's the announced criterion.


Using Jacobi's Two-Square Theorem, one finds that the number of ways to write $n^2=a^2+b^2$ for some integers $a,b\geq 0$ is precisely $$d_1(n^2)-d_3(n^2)+1,$$
where $d_i(n^2)$ denotes the number of positive divisors of $n^2$ which are congruent to $i$ modulo $4$.

Since the problem we're interested in requires $a$ and $b$ to be non-zero, we need to subtract $2$ from above count (corresponding to $n^2=n^2+0^2$ and $n^2=0^2+n^2$), yielding
$$d_1(n^2)-d_3(n^2)-1$$
number of ways to write $n^2=a^2+b^2$ for some integers $a,b\geq 1$.

To conclude, we obtain the following:

Proposition: An integer $n\geq 1$ is the sum of two positive squares precisely when $$d_1(n^2)-d_3(n^2)\geq 2.$$


Can this criterion be made more simple? For instance, can it be stated in terms of $d_i(n)$ instead of $d_i(n^2)$?

Best Answer

If $\space n\space$ is a valid hypotenuse value, there are $\space 2^{x-1} \space $ primitive triples for each $\space n\space$ where $\space x\space$ is the number of “distinct” prime factors $\space (f \equiv 1 \pmod 4) \space $ of $\space n.\quad$ For example $\space 1105=5\times 13 \times 17 \space$ so there are $\space 2^{3-1}=4\space $ combinations of $\space n^2=1105^2=a^2+b^2.\space $

The criteria for $\space n\space$ to be a hypotenuse are somewhat simple.

For the hypotenuse of a primitive Pythagorean triple, one "insufficient" criterion is $\space n=4x+1,\space x\in\mathbb{N},\space$ insufficient because not all values of this form are valid.

A "sufficient" criterion for primitive triples is based on Euclid's formula shown here as $$A=m^2-k^2\quad B=2mk\quad n=m^2+k^2$$ If we solve the $\space n$-function for $\space k, \space$ any of a defined range of $\space m$-values that yields an integer indicates that $\space n\space$ is a valid hypotenuse. If no integer solutions are found, $\space n\space$ is not a hypotenuse of a primitive triple.

$$n=m^2+k^2\implies k=\sqrt{n-m^2}\\ \qquad\text{for}\qquad \bigg\lfloor\frac{ 1+\sqrt{2n-1}}{2}\bigg\rfloor \le m \le \big\lfloor\sqrt{n-1}\big\rfloor$$

The lower limit ensures $m>k$ and the upper limit ensures $k\in\mathbb{N}$.

e.g. $$n=41\implies \bigg\lfloor\frac{ 1+\sqrt{82-1}}{2}\bigg\rfloor=5 \le m \le \big\lfloor\sqrt{41-1}\big\rfloor=6\quad \\ \text{and we find} \quad m\in\{5\}\Rightarrow k\in\{4\}\\ F(5,4)=(9,40,41)\quad $$

Related Question