Find all positive integers $n$ for which $(n-1)!+1$ is a power of $n$ [duplicate]

Well, for primes $p < 1290,$ those for which $$ 1 + (p-1)! \equiv 0 \pmod{p^2}$$ are the three $$\{ 5, \; \; 13, \; \; 563 \}$$

As soon as $p \geq 7,$ we have $(p-1)! > p^3,$ so we need $ 1 + (p-1)! \equiv 0 \pmod{p^3},$ and, in fact, $ 1 + (p-1)! \equiv 0 \pmod{p^4}.$ Quite rare.


This is really an old problem in ML. Note that, the equation doesn't hold for primes $>5$ which is in fact the Liouvilles'theorem