Sums of four coprime squares

Let $R(n)$ denote the number of ways of writing $n$ as a sum of $4$ squares, and $r(n)$ the number of ways where gcd of $(a,b,c,d) =1$. Then grouping representations of $n$ as a sum of $4$ squares according to the gcd of the variables, clearly we have $$ R(n) = \sum_{k^2 | n} r(n/k^2), $$ and so by Mobius inversion $$ r(n) = \sum_{k^2| n} \mu(k) R(n/k^2). $$

Now by Jacobi's four square theorem, $R(n)$ is given explicitly as $8$ times a multiplicative function $F(n)$ defined on prime powers by $$ F(2^k) = 3 \text{ for all } k\ge 1, $$ and, for odd primes $p$,
$$ F(p^k) = p^k + p^{k-1} + \ldots + 1. $$ So $r(n)$ is $8$ times a multiplicative function $f(n)$ which is defined on prime powers by $$ f(2)= 3; \ \ f(4) = 2;\ \ f(2^k)=0 \text{ for } k \ge 3, $$ and for odd primes $p$ and $k\ge 1$ $$ f(p^k) = p^k + p^{k-1}. $$


As Lucia noticed, if $8\mid n$, then $a,b,c$, and $d$ must be even, so that there is no "co-prime representation". If $8\nmid n$ with $n$ large enough, one can argue as follows.

Find a positive integer $d<\sqrt n$ such that

  • $d$ is co-prime with $n$;
  • $d$ and $n$ are of different parity;
  • moreover, if $n\equiv 3\pmod 8$, then $d\equiv 0\pmod 4$, and if $n\equiv 7\pmod 8$, then $d\equiv 2\pmod 4$.

One readily verifies that $d^2\not\equiv n+1\pmod 8$, as a result of which $n-d^2$ is not of the form $4^u(8v+7)$ (where $u$ and $v$ are non-negative integers). Therefore, by Legendre's three-square theorem, $n-d^2$ is a sum of three squares: $n-d^2=a^2+b^2+c^2$. This yields $n=a^2+b^2+c^2+d^2$, and co-primality of $d$ and $n$ ensures that $\gcd(a,b,c,d)=1$.