Find all natural numbers $n$ and $m$ for which $n^m=(n-1)!+1$ [duplicate]

Find all natural numbers $n$ and $m$ for which $$n^m=(n-1)!+1.$$

By the Wilson theorem, $n$ is prime. Obviously, $m < n$.

For example, some solutions $(n, m)$ are $(2, 1)$, $(3, 1)$ and $(5, 2)$.


You have found all the solutions.

Suppose there is a solution with $n>5.$ As you have noted, by Wilson's theorem, $n$ is prime. We have $$n^m-1=(n-1)!,$$ and dividing both sides by $n-1,$ $$(n-2)!=1+n+\cdots+n^{m-1}\tag{1}$$ Since $n>5$ is prime, $n-1$ is composite and $(n-1)|(n-2)!$ (Prove this.)

The preceding is Mindlack's hint, but I gather you haven't seen where to go from there.

Reducing both sides of $(1)$ modulo $n-1$ gives $0\equiv m\pmod{n-1}.$ Since $n-1$ divides $m$, we have $m\ge n-1.$

Now argue that $n^{n-1}>1+(n-1)!$