It's a standard theorem that the number of ways to write a positive integer N as the sum of two squares is given by four times the difference between its number of divisors which are congruent to 1 mod 4 and its number of divisors which are congruent to 3 mod 4. Alternatively, there are no such representations if the prime factorization of N contains any prime of form 4k+3 an odd number of times. If the prime factorization of N contains all such primes an even number of times, then we have
$$r_2(N) = 4(b_1+1)(b_2+1) \cdots (b_r+1)$$
where $b_1, \ldots, b_r$ are the exponents of the primes congruent to 1 mod 4 in the factorization of $N$.
For example, $325 = 5^2 \times 13$ can be written in $4(2+1)(1+1) = 24$ ways as a sum of squares. These are $18^2 + 1^2, 17^2 + 6^2, 15^2 + 10^2$, and the representations obtained from these by changing signs and/or permuting.
Is there an analogous formula in the three-square case? I know that an integer can be written as the sum of three squares if and only if it is not of the form $4^m (8n+7)$. There is a simple argument that shows that the number of ways to write all integers up to N as a sum of three squares is asymptotically $4\pi N^{3/2}/3$ -- representations of an integer less than $N$ as a sum of three squares can be identified with points in the ball in $\mathbb{R}^3$ centered at the origin with radius $N^{1/2}$. Differentiating, a "typical" integer near N should have about $2\pi N^{1/2}$ representations as a sum of three squares. From playing around with some data it looks like
$$\lim_{n \to \infty} {|\{k \le n, r_3(k)/k^{1/2} \le x \}| \over n}$$
might be a nonzero constant. That is, for each positive real $x$, the probability that a random integer $k$ can be written in no more than $x k^{1/2}$ ways approaches some constant in the open interval $(0, 1)$ as $k \to \infty$.
One way to prove this (if it is in fact true) would be if there were some formula for $r_3(k)$, in terms of the prime factorization, which is why I'm curious.
(I apologize if this is something that is well-known to number theorists, although I'd appreciate a pointer if it is. I am not a number theorist, I just play around with this sort of thing every so often and generate amusing conjectures.)