How do we count solutions of $a^2 + b^2 + c^2\equiv n\pmod p$?

103 Views Asked by At

Let's count number of solutions of $a^2 + b^2 + c^2 \equiv n\pmod p$ for each integer $n$ and each prime $p$. I'd start by just writing a function:

$$V_n(\mathbb{C}) = \left\{ (a,b,c) \in \mathbb{C}^3: a^2 + b^2 + c^2 = n \right\}$$

Maybe we could arrange this into some kind of Dirichlet series:

$$ f(s) = \prod_p \frac{\# V_n(\mathbb{F}_p)}{p^s} = \prod_p \frac{\# \{ (a,b,c): a^2 + b^2 + c^2 = n \}}{p^s} $$

This is now a Hasse-Weil zeta function or an Arithmetic zeta function, although I didn't mean to be that advanced.

Here's the sequence of numbers for $n = 3$. The left column is a prime number and the right column is the number of solutions. The result looks somewhat random:

[(2, 4),
 (3, 9),
 (5, 20),
 (7, 56),
 (11, 110),
 (13, 182),
 (17, 272),
 (19, 380),
 (23, 506),
 (29, 812)]

Here is $n=7$

[(2, 4),
 (3, 6),
 (5, 20),
 (7, 49),
 (11, 132),
 (13, 156),
 (17, 272),
 (19, 342),
 (23, 552),
 (29, 870)]
2

There are 2 best solutions below

0
On

Partial solution.

You can also rewrite it as: $$\sum_{u+v+w=n}\left(1+\left(\frac u p\right)\right)\left(1+\left(\frac v p\right)\right)\left(1+\left(\frac{w} p\right)\right)$$

This is because $1+\left(\frac mp\right)$ is the number of solutions to $x^2\equiv m\pmod{p}$.

This can then be rewritten as:

$$\sum_{u+v+w=n} \left(1+3\left(\frac{u}{p}\right)+3\left(\frac{uv}{p}\right)+\left(\frac{uvw}{p}\right)\right)$$

(Why?)

Now, $$\sum_{u+v+w=n} 1 = p^2.$$

Then convince yourself that $$\begin{align}\sum_{u+v+w=n} \left(\frac u p\right) &=0\\ \sum_{u+v+w=n}\left(\frac{uv}{p}\right)&=0 \end{align}$$

So the total is $$p^2+\sum_{u+v+w=n}\left(\frac{uvw}{p}\right)$$

Not sure how to evaluate that right-hand sum.


When $p=3,n=5$ the total is $12.$

This corresponds to three permutations each of $1^2+1^2+0^2\equiv 5,\, 2^2+2^2+0^2\equiv 5,$ ands six permutations of $2^2+1^2+0^2\equiv 5.$

3
On

Continuing on Thomas Andrews' answer, for $p>2$: $$\begin{align*}\sum_{u+v+w=n}\left(\frac{uvw}{p}\right)&= \sum_{u, v \neq 0}\left(\frac{(n-u-v)/uv}p\right) \\ &=\sum_{t\neq0}\left(\frac tp \right)\cdot \#\{(u,v) : uv \neq0, n-u-v=uvt\}\end{align*}$$ where the last equation in $(u,v)$ can be written as ($uvt\neq0$) $$(ut+1)(vt+1)=nt+1$$ which has:

  • $2p-3$ solutions for $nt+1=0$ (at least one of $u,v$ equals $-1/t$, both nonzero)
  • $p-3$ solutions for $nt+1 \neq 0$ and $p\nmid n$ ($u$ can be anything except $0,-1/t,n$ and this determines $v \neq 0$)
  • $p-2$ solutions for $nt+1 \neq 0$ and $p\mid n$ (same reason)

We get, for $p \nmid n$: $$\begin{align*}&=\sum_{t\neq-1/n}\left(\frac tp \right)\cdot (p-3) + \left(\frac {-n}p \right)(2p-3)\\ &=p\left(\frac {-n}p \right)\end{align*}$$ For $p\mid n$, there is no second term, the factor in the sum is $p-2$ and so the result is $0$, and the same formula holds.

Finally add $p^2$ to get $$\# V_n(\mathbb F_p) = p^2+p\left(\frac {-n}p \right)$$


Since you want all $p$, including $p=2$: since $u^2\equiv u \pmod 2$ we're counting points on an affine plane, so $4$ solutions for each $n$.