Solution (source code)

= Solution

Compare constant terms in the <polynomial> identity proved above. The constant term of $X^{p-1}-1$ is $-1$, while that of the product is $(-1)^{p-1}(p-1)!$. For odd $p$, this gives $(p-1)!\equiv-1\pmod p$. For $p=2$, the same conclusion holds because $1\equiv-1\pmod2$. Thus <Wilson's theorem> follows:
$$
\boxed{(p-1)!+1\equiv0\pmod p.}
$$