# When is a rational number a sum of three squares?

Which rational number $\dfrac pq$ can be written in the form $\left(\dfrac a b \right)^2 + \left( \dfrac c d \right)^2 + \left( \dfrac e f \right)^2$ where $a,c,e,p$ are nonnegative integers and $b,d,f,q$ are natural numbers?

It is known that a natural number can be written as sum of 3 squares iff it is not of the form $4^{a-1}(8b-1)$, where $a$ and $b$ is a natural number, due to a result of Legendre. Here by “squares” I mean they can be integers or non-integral rational. But I do not know how I can generalize these results to all rational numbers.

For the case of 2 squares it is much simpler. For a rational number $\dfrac pq$, if $p$ and $q$ are coprime, then it is a sum of 2 squares iff $p$ and $q$ can be written in terms of 2 squares, i.e. their prime decompositions do not contain a factor of the form $(4a-1)^{2b-1}$, where $a, b$ are natural numbers. But such result does not easily generalize to 3 squares.

#### Solutions Collecting From Web of "When is a rational number a sum of three squares?"

Your question is equivalent to $qp(bdf)^2$ is sum of three squares which is equivalent to not being of the form $4^a(8b-1)$ and because $(bdf)^2$ is of the form $4^x(8y+1)$ you can easily conclude that $pq$ is not of the form $4^a(8b-1)$, the converse is also true, so as an answer:

A rational number $\frac{p}{q}$ is sum of three rational squares if and only if $pq$ is not of the form $4^a(8b-1)$