# How prove this $(p-1)!\left(1+\frac{1}{2}+\frac{1}{3}+\cdots+\frac{1}{p-1}\right)\equiv 0\pmod{p^2}$

Show that $$(p-1)!\left(1+\dfrac{1}{2}+\dfrac{1}{3}+\cdots+\dfrac{1}{p-1}\right)\equiv 0\pmod{p^2}.$$

Maybe use this $$\dfrac{1}{k}+\dfrac{1}{p-k}=\dfrac{p}{k(p-k)}$$ and then I can't. Can you help me to prove it?

Thank you.

-
Adapting Wilson's theorem mod $p^2$? – PITTALUGA Nov 6 '13 at 12:09
I think the general expression is not an integer; at least for p=3,5. – user99680 Nov 6 '13 at 12:15
It is, since every denominator appears as a factor of $(p-1)!$. – Christoph Nov 6 '13 at 12:16
More is true: en.wikipedia.org/wiki/Wolstenholme%27s_theorem. – lhf Nov 6 '13 at 12:17
Ah, yes, I was adding incorrectly. – user99680 Nov 6 '13 at 12:18

The solution below is adapted from Notes on Wolstenholme’s Theorem by Timothy H. Choi.

Let $$S=(p-1)!\sum_{k=1}^{p-1} \frac1k$$ Using your insight $$\dfrac{1}{k}+\dfrac{1}{p-k}=\dfrac{p}{k(p-k)}$$ we have $$2S=(p-1)!\sum_{k=1}^{p-1} \left(\dfrac{1}{k}+\dfrac{1}{p-k}\right) = p\sum_{k=1}^{p-1} \frac{(p-1)!}{k(p-k)} = pS'$$ Note that $S'$ is an integer. Now $$\frac{(p-1)!}{k(p-k)} \equiv (k^2)^{-1} \bmod p$$ where the inverse is taken ${}\bmod p$. This is a consequence of Wilson’s Theorem. Hence $$S'\equiv \sum_{k=1}^{p-1} (k^2)^{-1} \equiv \sum_{k=1}^{p-1} k^2 = \frac{(p-1)p(2(p-1)+1)}{6} \equiv 0 \bmod p$$ This means that $2S\equiv 0 \bmod p^2$ and so $S\equiv 0 \bmod p^2$. (We need $p>3$ twice here.)

-

As others have noted, the congruence is not true for $p=3$, since $$2!\left(1+\frac 1 2\right)=2+1=3,$$ which is not divisible by $9$. We can still use what you suggested to prove the congruence holds $\operatorname{mod} p$. Let $p$ be an odd prime, then \begin{align*} (p-1)!\sum_{k=1}^{p-1} \frac 1 k &= (p-1)! \sum_{k=1}^{(p-1)/2} \left(\frac 1 k + \frac 1 {p-k}\right) \\&= (p-1)!\sum_{k=1}^{(p-1)/2} \frac{p}{k(p-k)} = p\sum_{k=1}^{(p-1)/2} \frac{(p-1)!}{k(p-k)}. \end{align*} Since $(p-1)!$ always contains $k$ and $(p-k)$ as a factor, the fractions in the sum are integers and the result is a multiple of $p$.

See lhf's answer for why it is even a multiple of $p^2$ as long as $p>3$.

-
The congruence will hold for any $p>3$ modulo $p^2$. That's Wolstenholme's theorem as lhf pointed out. – EuYu Nov 6 '13 at 12:39
I adapted my post and referencered lhf's answer, thanks for your comment! – Christoph Nov 6 '13 at 12:54