>From "Representations of Integers as Sums of Squares" by
Emil Grosswald, Springer, 1985:
n is representable with 3 squares iff n is not of the form
4^a (8k+7).
R3(n) is # of _primitive_ solutions; r3(n) is # of all solutions.
r3(n) = sum(d^2|n, R3(n/d^2))
R3(n) was determined by Gauss, although not in the following form.
Let h = number of classes of primitive binary quadratic forms,
corresponding to the discriminant D=-n if n=3 (mod 8), D=-4n
if n=1,2,5,6 (mod 8), and let d_1=1/2, d_3=1/3, d_n=1 otherwise.
Then R3(n) = 12 h d_n, if n=1,2,5,6 (mod 8), 24 h d_n, if n=3 (mod 8).
Also, if n is squarefree and (r/n) is the Jacobi symbol,
R3(n) = 24 sum(r=1,[n/4],(r/n)) if n=1 (mod 4),
8 sum(r=1,[n/2],(r/n)) if n=3 (mod 8).
Don't ask me if I can follow the proof -- I can barely understand
the statement.
I assume that there are no simpler formulations, else Grosswald
would have shown them.
-----
At 12:21 PM 11/20/02 -0800, Eugene Salamin wrote:
>There is a nice way to calculate the number r2(n),
>n>0, of integer solutions (x,y) of
>
> x^2 + y^2 = n.
>
>Factor n as
>
> n = p1^a1 p2^a2 ... q1^b1 q2^b2 ... 2^c,
>
>where the p's are primes == 1 mod 4, and the q's are
>primes == 3 mod 4. Then
>
> r2(n) = if any b is odd, then 0
> else, 4 (1 + a1) (1 + a2) ... .
>
>Is there a similar formula for the number r3(n) of
>integer solutions (x,y,z) of
>
> x^2 + y^2 + z^2 = n ?