Here is some background information on the problem I am trying to solve. I start with the following equation:
$n^2(a^2 + b^2) = x^2 + y^2$, where $n, a, b, x, y \in \mathbb Z$, and $a \ge b \gt 0$, $n \gt 0$, and $x \ge y \gt 0$.
For given values of $a$ and $b$ and some $n$, I need to find $x$ and $y$ such that $x$ is as large as possible (and $y$ as small as possible). The value of $n$ is up to me as long as allowable values are linear ($n = kn_0$). A naive approach is to use the distributive property to set $x = na$ and $y = nb$, but this causes $x$ and $y$ to grow at the same rate and doesn't guarantee $x$ is as large as possible.
I realized that if $n^2$ is the sum of two square integers (the length of the hypotenuse of a Pythagorean triangle), then I can use the Brahmagupta–Fibonacci identity to find values for $x$ and $y$ that are as good or better than using the distributive property:
$(a^2 + b^2)(c^2 + d^2) = (ac + bd)^2 + (ad - bc)^2$
$n^2 = c^2 + d^2$, where $c \gt d$
So for example, if $a = 2$, $b = 1$, and $n = 5$, then instead of
$5^2(2^2 + 1^2) = 10^2 + 5^2 = 125$, so that $x = 10$ and $y = 5$ we get
$(4^2 + 3^2)(2^2 + 1^2) = (4\cdot2 +3\cdot1)^2 + (4\cdot1 - 3\cdot2)^2 = 11^2 + (-2)^2 = 125$, so $x = 11$ and $y=2$
My question is, does this strategy always find $x$ to be the largest possible integer whose square is less than $n^2(a^2 + b^2)$, for $n$ a sum of two square integers?