# Prove that $\sum_{n = 1}^{p - 1} n^{p - 1} \equiv (p - 1)! + p \pmod {p^2}$ with $p$ being an odd prime

First, I have to admit that I have already asked the same question on MSE several days ago. If I am bending any rules, I apologize for that and moderator can delete or close this question without warning. The problem has received a number of upvotes on MSE but with no suggestions or hints provided from the community.

I need to prove the following:

$$\sum_{n = 1}^{p - 1} n^{p - 1} \equiv (p - 1)! + p \pmod {p^2}$$

...with $$p$$ being an odd prime number. I'm pretty much sure that the statement is correct (I have tested it by computer for many values of $$p$$ and did not find an exception).

What puzzles me is the fact that the statement is trivial and obviously true for$$\pmod p$$. The left-hand side is congruent to $$-1 \pmod p$$ by Fermat's little theorem, and the right-hand side is also congruent to $$-1 \pmod p$$ by Wilson's theorem.

However, I am unable to "lift the exponent" and go from$$\pmod p$$ to$$\pmod {p^2}$$. Maybe the sum on the left could somehow be transformed using the existence of a primitive root$$\pmod {p^2}$$.

Thanks and happy holidays!

• I have already mentoined that the problem is crossposted. The answer is just a hint. The question comes from a number theory book that does not even mention Beronoulli numbers so I suppose there is a simple(r) solution. The hint is pretty useless to me. – Oldboy Dec 31 '18 at 10:42
• Did you try to adapt Lagrange's alternate proof of Wilson's theorem? It uses finite differences of the sequence $n^{p-1}$. fr.m.wikipedia.org/wiki/… – François Brunault Dec 31 '18 at 11:30
• @FrançoisBrunault Thanks for the hint, I'll check that! – Oldboy Dec 31 '18 at 11:31

The result can be easily proved without using Bernoulli numbers. If $$a$$ and $$b$$ are integers not divisible by an odd prime $$p$$, then \begin{align}(ab)^{p-1}-1=&b^{p-1}(a^{p-1}-1)+(b^{p-1}-1) \\\equiv& (a^{p-1}-1)+(b^{p-1}-1)\pmod {p^2}.\end{align} Thus \begin{align*}\sum_{n=1}^{p-1}(n^{p-1}-1)\equiv& \prod_{n=1}^{p-1}n^{p-1}-1=((p-1)!+1-1)^{p-1}-1 \\\equiv &(p-1)((p-1)!+1)(-1)^{p-2}\equiv(p-1)!+1\pmod{p^2}\end{align*} and hence the desired congriuence follows.
You may use Faulhaber's formula $$\sum_{k=1}^p k^{p-1}=\frac{p^p}p+\frac12 p^{p-1}+\sum_{k=2}^{p-1} \frac{B_k}{k!}\,(p-1)^{\underline{k-1}}\,p^{p-k}.$$ All summands except this corresponding to $$k=p-1$$ are divisible by $$p^2$$ (they are not integers, but corresponding Bernoulli numbers do not have $$p$$ in denominators). For $$k=p-1$$ you get $$pB_{p-1}$$. For evaluating it modulo $$p^2$$ we may use the formula for Bernoulli numbers via Worpitzky numbers: $$B_{p-1}=\sum_{k=0}^{p-1} (-1)^k\frac{k!}{k+1}\left\{\matrix{p\\k+1}\right\}.$$ All summands except corresponding to $$k=0$$, $$k=p-1$$ are divisible by $$p$$ (the corresponding Stirling numbers of the second kind are divisible by $$p$$ dues to the action of the cyclic shifts group on the partitions of $$\{1,2,\dots,p\}$$). For $$k=0$$ and $$k=p-1$$ we get $$pB_{p-1}\equiv (p-1)!+p\pmod {p^2}$$ as desired.