<s>[INST] Lemma on switching between mod $p$ and mod $p^2$ or mod $p^3$ Can someone help me prove the following lemma? Also can it be strengthened?
Let $p\geq 5$ be a prime number. Prove that if $p|a^2+ab+b^2$, then $p^3|(a+b)^p-a^p-b^p$
Here is what I tried:
We want to show $$p^3|a^{p-1}\binom{p}{1}b+a^{p-2}\binom{p}{2}b^2+\dots+a\binom{p}{p-1}b^{p-1}$$
It is easy to see that all the terms in the expression divide $p$, so we want to show:
$$\begin{align*} a^{p-1}b\frac{(p-1)!}{(p-1)!}+a^{p-2}b^2\frac{(p-1)!}{2!(p-2)!}+a^{p-3}b^3\frac{(p-1)!}{3!(p-3)!}+\dots &\equiv a^{p-1}b-a^{p-2}b^2\frac{1}{2!(p-2)!}\dots \\ &\equiv 0\pmod{p} \end{align*}$$
from Wilson's Theorem. But I do not know how to do that, as the expression is quite ugly. Also, we ultimately want to show it is divisble by $p^3$ and not just $p$. Finally, I could not find a way to use the given condition. Any ideas are appreciated.
I found the lemma in a solution to the problem here:
http://artofproblemsolving.com/community/c6h514444p2890151
 [/INST] Here is the proof anticipated by Stefan4024, based on this question linked to in his answer.
We first show that if $p \equiv 1 \pmod 6$, then
$$
  p(a^2 + ab + b^2)^2 \,\mid\, (a+b)^p - a^p - b^p .
$$
Consider some fixed $b$, and let $f(x)$ be the polynomial
$$
  f(x) = (x + b)^p - x^p - b^p.
$$
Let $\omega = e^{2\pi i / 3}$ be a primitive third-root of unity, and note that since $1 + \omega + \omega^2 = 0$, that we have that $1 + \omega = -\omega^2$ is a sixth-root of unity.
We will show that $\omega b$ is a root of both $f(x)$, and its derivative $f^\prime (x)$.
We have that $f(\omega b)$ is equal to
$$
  (\omega b + b)^p - (\omega b)^p - b^p = b^p \left( (1 + \omega)^p - \omega^p - 1 \right)
$$
Since $\omega^3 = (1 + \omega)^6 = 1$, and $p-1$ is divisible by $6$, we have that $\omega^p = \omega$, and $(1 + \omega)^p = (1 + \omega)$. Thus we have that
$$
  f(\omega b) = b^p \left( (1 + \omega) - \omega - 1 \right) = 0.
$$
Thus $\omega b$ is a root of $f$. Similarly,
$$
  f^\prime (\omega b) = p (\omega b + b)^{p-1} - p(\omega b)^{p-1} = p b^{p-1} \left( (1 + \omega)^{p-1} - \omega^{p-1} \right) = p b^{p-1} (1 - 1) = 0.
$$
Thus $\omega b$ is a root of both $f$ and $f^\prime$, from which it follows that $(x - \omega b)^2$ is a factor of $f$. Since $f$ has real coefficients, $(x - \bar{\omega})^2$ is also a factor of $f$, and we see that $(x^2 + xb + b^2)^2$ is a factor of $f$.
Now it is a well-known fact that for $1 \leq k \leq (p-1)$, that the binomial coefficient $\binom{p}{k}$ is divisible by $p$, and so we see by the binomial theorem that all of the coefficients of $f$ are divisible by $p$. Thus $\frac{1}{p} f$ is a polynomial with integer coefficients, and is divisible by $(x^2 + xb + b^2)^2$, which is a monic polynomial with integer coefficients. It follows that we can write
$$
  \frac{1}{p} f(x) = (x^2 + xb + b^2)^2 \cdot g(x)
$$
where $g(x)$ is some polynomial with integer coefficients. From this it follows easily that $f(a) = (a + b)^p - a^p - b^p$ is divisible by $p(a^2 + ab + b^2)^2$ if $p \equiv 1 \pmod 6$.
Now suppose that $p \,\mid\, a^2 + ab + b^2$. We will show that $p \equiv 1 \pmod 6$, so that
$$
  p^3 \,\mid\, p(a^2 + ab + b^2)^2 \,\mid\, (a + b)^p - a^p - b^p .
$$
We note that
$$
  p \,\mid\, 4a^2 + 4ab + 4b^2 = (2a + b)^2 + 3b^2.
$$
If $p \,\mid\, b$, then we see that we must also have that $p \,\mid\, a$, and so $(a + b)^p - a^p - b^p$ is divisible by $p^p$, and so is certainly divisible by $p^3$. Suppose now that $b$ is not divisible by $p$. Then we have that
$$
  \left((2a + b) \cdot b^{-1} \right)^2 \equiv -3 \pmod p
$$
where $b^{-1}$ is the multiplicative inverse of $b$ modulo $p$, and so we see that $-3$ is a quadratic residue modulo $p$.
Thus
$$
  \left( \frac{-1}{p} \right)\left( \frac{3}{p} \right) = \left( \frac{-3}{p} \right) = 1
$$
where $\left( \frac{\;}{} \right)$ is the Jacobi symbol. If $p \equiv 1 \pmod 4$, then
$$
  \left( \frac{-1}{p} \right) = 1
$$
and by quadratic reciprocity,
$$
  \left( \frac{3}{p} \right) = \left( \frac{p}{3} \right) = 
  \begin{cases}
    1 & \text{ if } p \equiv 1 \pmod 3 \\
   -1 & \text{ if } p \equiv 2 \pmod 3
  \end{cases}.
$$
We see that in this case, we must have that $p \equiv 1 \pmod 3$.
On the other hand, if $p \equiv 3 \pmod 4$, then we know that
$$
  \left( \frac{-1}{p} \right) = -1
$$
and so we must have
$$
  \left( \frac{3}{p} \right) = -1.
$$
Since $3$ and $p$ are both $3$ mod $4$, quadratic reciprocity in this case gives us that
$$
  -1 = \left( \frac{3}{p} \right) = -\left( \frac{p}{3} \right),
$$
and so we again have that $p \equiv 1 \pmod 3$.
In either case, we see that $p \equiv 1 \pmod 3$, and so $p \equiv 1 \pmod 6$, and the result follows.
</s>