Given an odd prime $p$, find the number of elements in the set $\left\{(x, y) \mid x^{2}+y^{2} \equiv a(\bmod p) ; x, y \in\{0,1,2, \mathrm{~L}, p-1\}\right\}$.
Four, first prove a lemma: $p$ is an odd prime, $p-1$ does not divide $a$, where $a$ is a positive integer, then
$$
1^{a}+2^{a}+\mathrm{L}+(p-1)^{a} \equiv 0(\bmod p)
$$

Proof: Without loss of generality, assume $1 \leq a \leq p-2$. By Lagrange's theorem, the equation $x^{a} \equiv 1(\bmod p)$ has at most $a$ solutions.

Then there exists $g$ such that $g$ is not congruent to $0$ modulo $p$, and $g^{a}$ is not congruent to $1$ modulo $p$. Since $1,2, \mathrm{~L}, p-1$ form a reduced residue system modulo $p$, $g, 2 g, \mathrm{~L},(p-1) g$ also form a reduced residue system modulo $p$. Hence
$$
\begin{array}{l}
1^{a}+2^{a}+\mathrm{L}+(p-1)^{a} \equiv g^{a}+(2 g)^{a}+\mathrm{L}+((p-1) g)^{a}(\bmod p) \\
\text { then }\left(g^{a}-1\right)\left(1^{a}+2^{a}+\mathrm{L}+(p-1)^{a}\right) \equiv 0(\bmod p), \text { so } 1^{a}+2^{a}+\mathrm{L}+(p-1)^{a} \equiv 0(\bmod p) ;
\end{array}
$$

Back to the original problem: Let the number of elements in the set be $S$. We first show that if $a \equiv 0(\bmod p)$, then
$$
S=\left\{\begin{array}{l}
2 p-1, p \equiv 1(\bmod 4) \\
1, p \equiv 3(\bmod 4)
\end{array} \text { . (1) When } p \equiv 3(\bmod 4) \text {, if } x^{2}+y^{2} \equiv 0(\bmod p)\right. \text {, then }
$$
$x^{2} \equiv-y^{2}(\bmod p)(*)$, and $(-1)^{\frac{p-1}{2}}=-1$, so by Euler's criterion, -1 is not a quadratic residue modulo $p$, hence if $(*)$ holds, it must be that $x \equiv y \equiv 0(\bmod p)$, giving 1 solution; (2) When $p \equiv 1(\bmod 4)$, by Euler's criterion, there exists $m$ such that $m^{2} \equiv-1(\bmod p)$, then for $x \neq 0$, since $x^{2}+(m x)^{2} \equiv x^{2}+(-m x)^{2} \equiv\left(1+m^{2}\right) x^{2} \equiv 0(\bmod p)$, we know that $(x, m x),(x,-m x)$ are both integer pairs that satisfy the condition, hence there are $(p-1) \times 2+1=2 p-1$ solutions.

Next, we prove that $S$ is an even number not greater than $2 p$.
Since $0,1,2^{2}, \mathrm{~L},\left(\frac{p-1}{2}\right)^{2}, a, a-1, a-2^{2}, \mathrm{~L}, a-\left(\frac{p-1}{2}\right)^{2}$ are $p+1$ numbers, at least two of them must be congruent modulo $p$. Without loss of generality, assume $x^{2} \equiv a-y^{2}(\bmod p)$, i.e., $x^{2}+y^{2} \equiv a(\bmod p)$, so $S \geq 1$. For each $y$, there are at most two $x$, so $S \leq 2 p$. (1) For integer pairs where $x \neq 0$ and $y \neq 0$, if $x^{2}+y^{2} \equiv a(\bmod p)$, then $(x, y),(x,-y)$ satisfy the condition, and there are an even number of such integer pairs; (2) If $x y=0$, assume $x=0$, then $y^{2} \equiv x^{2}+y^{2} \equiv a(\bmod p)$, so $(0, y),(0,-y)$ satisfy the condition, and there are an even number of such integer pairs, hence $S$ is even. Note that the number of solutions when $y=k$ is congruent to $\left(a-y^{2}\right)^{\frac{p-1}{2}}+1$ modulo $p$, so
$$
\begin{aligned}
S & \equiv \sum_{y=0}^{p-1}\left(\left(a-y^{2}\right)^{\frac{p-1}{2}}+1\right) \\
& \equiv \sum_{y=1}^{p-1}\left(\sum_{k=0}^{\frac{p-1}{2}}(-1)^{\frac{p-1}{2}-k} C_{\frac{p-1}{k}}^{k} a^{k} y^{p-1-2 k}+1\right)+a^{\frac{p-1}{2}}+1 \\
& \equiv \sum_{k=0}^{\frac{p-1}{2}}(-1)^{\frac{p-1}{2}-k} C_{\frac{p-1}{k}}^{\frac{k}{2}} \sum_{y=1}^{p-1} y^{p-1-2 k}+a^{\frac{p-1}{2}} \\
& \equiv(p-1) a^{\frac{p-1}{2}}+(-1)^{\frac{p-1}{2}}(p-1)+a^{\frac{p-1}{2}} \equiv(-1)^{\frac{p+1}{2}}(\bmod p)
\end{aligned}
$$

i.e., $S=\left\{\begin{array}{l}p-1, p \equiv 1(\bmod 4) \\ p+1, p \equiv 3(\bmod 4)\end{array}\right.$; In summary, when $a \equiv 0(\bmod p)$, $S=\left\{\begin{array}{l}2 p-1, p \equiv 1(\bmod 4) \\ 1, \quad p \equiv 3(\bmod 4)\end{array}\right.$; When $a$ is not congruent to $0$ modulo $p$, $S=\left\{\begin{array}{l}p-1, p \equiv 1(\bmod 4) \\ p+1, p \equiv 3(\bmod 4)\end{array}\right.$;