# Number of solutions to $a^2-b^2+c^2 = k\pmod{p}$

Let $k\neq 0$ be a fixed integer. How many triplets $(a,b,c)$ are there satisfying $$a^{2}-b^{2}+c^{2}\equiv k\pmod{p}$$ I know that if $c=0$, then there are $p-1$. Not sure for the general case

Let $N_k$ be the number of solutions.

Define the Gauss sum $\tau=\sum_{a=0}^{p-1}\zeta^{a^2}$ where $\zeta=\exp(2\pi i/p)$. Then $$\tau^2\overline{\tau}=\sum_{a,b,c=0}^{p-1}\zeta^{a^2-b^2+c^2} =\sum_{k=0}^{p-1} N_k\zeta^k.$$ So $$p\tau=p\sum_{k=0}^{p-1}\left(\frac kp\right)\zeta^k=\sum_{k=0}^{p-1} N_k\zeta^k=\sum_{k=1}^{p-1}(N_k-N_0)\zeta^k.$$ Here $\left(\frac kp\right)$ is the Legendre symbol. Since $\zeta,\ldots,\zeta^{p-1}$ are linearly independent over $\Bbb Q$, then it follows that $N_k-N_0=p\left(\frac kp\right)$. So $$N_k=N_0+p\left(\frac kp\right).$$ Adding over all $k$ gives $$p^3=pN_0$$ so $$N_k=p^2+p\left(\frac kp\right).$$

• Emm. You have a great name :) BTW, can't this be done without using Gauss sums?? – crskhr Jun 1 '17 at 17:08
• @S.C. but Gauss sums are great fun! – Lord Shark the Unknown Jun 1 '17 at 17:12
• They are but i am not used to them as of now. There is too much machinery being used here. – crskhr Jun 1 '17 at 17:15
• Why does $p\tau = \tau^2 \bar{\tau}$? – Carl Schildkraut Jun 1 '17 at 17:58
• @CarlSchildkraut $|\tau|^2=p$ – Lord Shark the Unknown Jun 1 '17 at 18:01

What is the problem if $c\neq 0$?

Fix $c$, then $c^2$ leaves some remainder when divided by $p$, now if you move $c^2$ to the left-hand side of the equation, and let $k-c^2$(mod p)=$k$', so we have to find the number of solutions

$a^2+b^2=k'$ (mod p)

As you said if $k'\neq 0$ then it has $p-1$ solutions, so if $k$ is not a square modulo $p$(i.e $k'$ is not zero for any value of $c$) then the number of solutions of the original equation is $(p-1) \times p$.

Note that $a^2+b^2=0$ (mod p) has $p+(p-1)=2p-1$ solutions.

Now say $k'=0$ for some $c\neq 0$ (i.e. $k$ is a quadratic residue modulo $p$ and $k\neq 0$), then for exactly $2$ values of $c$, $k'=0$ and the equation will have $2p-1$ solutions for those $2$ values and for the rest $p-2$ values of $c$ we will have $p-1$ pairs of $(a,b)$ for each value of $c$, hence the total number of solutions of the original congruence in this case is $(p-2)\times (p-1)+2(2p-1)=p^2+p$, when $k\neq 0$ is a quadradic residue modulo $p$.

If $k=0$, then for $c=0$ the congruence has exactly $2p-1$ solutions and for all other $p-1$ values of $c$ the congruence has $p-1$ solutions for each $c$. Hence, in this case, the total number of solution is $(p-1)^2+2p-1=p^2$

• I got $p^2+p$ solutions when $k$ is a quadratic residue. – Lord Shark the Unknown Jun 1 '17 at 18:01
• take $p=3$ , $k=1$, i think i'm getting $9$ solutions, pls check, either your or my answer is wrong – Arpan1729 Jun 1 '17 at 18:08
• (0,0,1), (1,1,1), (2,2,1), (1,2,1), (2,1,1), (1,2,2), (2,1,2), (1,1,2), (2,2,2), (0,0,2), (1,0,0), (2,0,0) – Lord Shark the Unknown Jun 1 '17 at 18:37
• now both of our solutions are correct – Arpan1729 Jun 1 '17 at 21:56
• what is your real name? where do you study? – Arpan1729 Jun 13 '17 at 1:56