[guided]We have $s \in \mathbb{Z}$ with $s^2 \equiv -1 \pmod p$ and must produce integers $a, b$ with $a^2 + b^2 = p$. The strategy is to find $a, b$ with two properties: (i) $a \equiv s b \pmod p$, which forces $a^2 + b^2 \equiv (s^2 + 1) b^2 \equiv 0 \pmod p$, and (ii) $|a|, |b|$ small enough that $a^2 + b^2 < 2 p$, pinning the value to the unique positive multiple $p$ of $p$ in the interval $(0, 2p)$.
Why "small enough" means $|a|, |b| \le \sqrt{p}$: this gives $a^2 + b^2 \le 2 p$, which together with $(a,b) \ne (0,0)$ forces $a^2 + b^2 \in \{p, 2p\}$. The pigeonhole argument produces the pair.
Set $m = \lfloor \sqrt p \rfloor$. Consider the map
\begin{align*}
\Phi : \{0, 1, \dots, m\}^2 &\to \mathbb{Z}/p\mathbb{Z} \\
(u, v) &\mapsto u - s v \pmod p.
\end{align*}
Why this specific map? Because if $\Phi(u_1, v_1) = \Phi(u_2, v_2)$, the difference $(a, b) := (u_1 - u_2, v_1 - v_2)$ satisfies $a \equiv s b \pmod p$ automatically — exactly condition (i).
The domain of $\Phi$ has $(m+1)^2$ elements. We need $(m+1)^2 > p$: since $m = \lfloor \sqrt p \rfloor$, we have $m + 1 > \sqrt p$, hence $(m+1)^2 > p$, strictly. By the pigeonhole principle applied to $\Phi$, there exist distinct pairs $(u_1, v_1) \ne (u_2, v_2)$ in $\{0, \dots, m\}^2$ with the same image. Setting $a = u_1 - u_2$ and $b = v_1 - v_2$ gives $a \equiv s b \pmod p$, $|a| \le m$, $|b| \le m$, and $(a, b) \ne (0, 0)$.
Now we verify the two conclusions:
**Divisibility:** Since $s^2 \equiv -1 \pmod p$,
\begin{align*}
a^2 + b^2 \equiv s^2 b^2 + b^2 \equiv (s^2 + 1) b^2 \equiv 0 \pmod{p}.
\end{align*}
So $p \mid a^2 + b^2$.
**Bounds:** $(a, b) \ne (0, 0)$ gives $a^2 + b^2 > 0$. Also $|a|, |b| \le m$, so
\begin{align*}
a^2 + b^2 \le 2 m^2 \le 2 p.
\end{align*}
Could $a^2 + b^2 = 2 p$? This would require $a^2 = b^2 = m^2 = p$, making $p$ a perfect square. But $p$ is an odd prime, so $p \ne m^2$. Hence $a^2 + b^2 < 2 p$.
**Conclusion:** The positive multiples of $p$ in the open interval $(0, 2 p)$ consist of the single value $p$. Thus $a^2 + b^2 = p$.
A final remark: why did we choose $u, v \in \{0, \dots, m\}$ rather than $\{-m, \dots, m\}$? The asymmetric range maximises the density of the domain: $(m + 1)^2$ over $p$, giving an "extra" $(m+1)^2 - p > 0$ collisions. Using a symmetric range would not save anything and would complicate the size bound on the difference.[/guided]