Finding all primes $p$ satisfying $p=a^2+b^2$ and $p$ divides $a^3+b^3-4$ . 
Determine all primes $p$ such that there exist integers $a, b$ satisfying $p=a^2+b^2$ and $a^3+b^3-4$ is divisible by $p$.

So, $p | ab(a+b)+4$ after writing $a^3+b^3-4=(a+b)(p-ab)-4$ and $p=2$ is a solution if $p|4$. If $p$ doesn't divide $4$, $ab(a+b)\equiv -4 \pmod p$. Also, $p=4m+1$ for some integer $m$ by Fermat's 2-square theorem.It seems like $5$ and $2$ are the only primes that satisfy the conditions but I can't seem to prove it.
I've tried manipulating the stuff around but I'm not getting anything. Can anyone give a small hint? Thanks.
 A: Observe, $$\begin{align*} 2ab(a+b)+8&\equiv 0 &&\pmod p \\  2ab&\equiv (a+b)^2&&\pmod p\\ \therefore\;\; (a+b)^3+8&\equiv 0 &&\pmod p \end{align*}$$
So, $$p|(a+b+2)\; \;\text{or}\; \;p|(a+b)^2-2(a+b)+4$$

Case 1: $$p|a+b+2$$
$$a^2+b^2|a+b+2\implies a^2+b^2\le a+b+2 \le \sqrt{2(a^2+b^2)}+2$$
$$\therefore\;\; p\le \sqrt{2p}+2 \;\Leftrightarrow\; p\in \{2,3,5\}$$

Case 2:
$$p|2ab-2(a+b)+4\implies p=2 \;\; \text{or}\;\; p|ab-a-b+4$$
$$a^2+b^2|ab-a-b+4\implies a^2+b^2\le ab-a-b+4\le ab+4\le \frac{a^2+b^2}{2}+4$$
$$\therefore\;\; p\le \frac{p}{2}+4 \;\Leftrightarrow\; p\in \{2,3,5,7\} $$

If $p=2$, we can set, $(a,b)=(1,1)$
If $p=5$, we can set, $(a,b)=(1,2)$
If $p=3$ or $p=7$,we have, $p=a^2+b^2$ is impossible by Fermat's theorem on sums of two squares.
A: Assume $p>2$, and let $s=a+b$. Then
$$ab=\frac{(a+b)^2-(a^2+b^2)}2\equiv \frac{s^2}2\pmod p.$$
Now,
$$a^3+b^3=(a+b)(a^2-ab+b^2)\equiv (a+b)(-ab)\equiv -\frac{s^3}2\pmod p.$$
This implies that $s^3\equiv -8$ modulo $p$. This means that either $p\mid s+2$ or $p\mid s^2-2s+4$.
In the first case,
$$s\geq p-2\implies p=a^2+b^2\geq \frac{(a+b)^2}2\geq \frac{(p-2)^2}2,$$
which implies $p\leq 5$. In the second case,
$$p\mid s^2-2s+4-p=2ab-2(a+b)+4.$$
Since $p>2$, this means $p\mid ab-a-b+2$, and thus $p\leq ab-a-b+2<ab$. However, $a^2+b^2\geq ab$, so this can't occur.
