Lemma on switching between mod $p$ and mod $p^2$ or mod $p^3$

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.


A discussion here shows that if $p=6k+1$, then $p^3 \mid (a+b)^p - a^p - b^p$, while if $p=6k+5$ then $p^2 \mid (a+b)^p - a^p - b^p$. Now the problem reduces here to proving that $p \mid a^2 + ab + b^2 \implies p = 6k+1$, which I'm still unable to prove.

Nonetheless I have an "elementary" proof for: $p \mid n^2 + n + 1 \implies p^2 \mid (n+1)^p - n^p - 1^p$, which is enough for the problem in the link.

Obviously $p \not \mid n,(n+1)$. Now from LTE, as $p \mid n^2 + n + 1 $ and $p\not \mid n^2, p \not \mid n+1$ we have:

$$v_p(n^{2p} + (n+1)^p) = v_p(n^2 + n + 1) + v_p(p) = 2 \implies p^2 \mid n^{2p} + (n+1)^p$$

Now applying LTE again, as $p \mid n^2 + n + 1 $ and $p\not \mid n^2 + n, p \not \mid 1$ we have that:

$$v_p((n^2+n))^p + 1^{p}) = 2 \implies p^2 \mid (n^2 + n)^p + 1$$

Now using that $(n+1)^p \equiv - n^{2p} \pmod {p^2}$ we have that:

$$p^2 \mid (n^2 + n)^p + 1 = n^p(n+1)^p + 1 \implies p^2 \mid -n^pn^{2p} + 1 \implies p^2 \mid n^{3p} - 1$$

But $p \not \mid n^p - 1$ by Fermat's Little Theorem and as $n^{3p} - 1 = (n^p-1)(n^{2p} + n^p + 1)$ we have that $p^2 \mid n^{2p} + n^p + 1$. But now:

$$p^2 \mid n^{2p} + n^p + 1 \implies p^2 \mid -(n+1)^p + n^p + 1$$

Hence the proof.


Also I nice idea would be to ask the person who solved the problem on the forum to explain how he obtained such a thing. I think that he wouldn't mind explaining.