Does $p^2\mid n^n\cdot n!+1$ imply $p=n+1$? I wonder whether we can find all primes $\ p\ $ such that there is a positive integer $\ n\ $ with $$p^2\mid n^n\cdot n!+1.$$
For a given prime $\ p$, we only need to check upto $\ n=p\ $ since $\ p<n\ $ cannot divide $n^n\cdot n!+1$.
Up to $p=10^4$, I only found the following pairs $(n,p)$:

*

*$[2,3]$

*$[10,11]$

*$[106,107]$

*$[4930,4931]$

In all those cases we have $\ p=n+1$. Is this a necessary condition?

By the way, for $$p^2\mid n^n\cdot n!-1$$ I only found the solution $\ [44,107]$, if we rule out $\ n=1$. We even have $ 107^3\mid 44^{44}\cdot 44!-1$. Search limit is again $\ p=10^4$ Are there more solutions?
 A: I. For prime $p=n+1$,$$n^n\cdot n!+1=(p-1)^{p-1}\cdot (p-1)!+1$$
And since by Fermat's Little Theorem $(p-1)^{p-1}\equiv1\pmod p$, and by Wilson's Theorem $(p-1)!\equiv-1\pmod p$,
then$$n^n\cdot n!+1\equiv 1\cdot -1+1=0\pmod p$$Hence$$p|n^n\cdot n!+1$$ when $p=n+1$, i.e. $p=n+1$ is a sufficient condition for $p|n^n\cdot n!+1$.
But it is not a necessary condition, since e.g. $19|18^{18}\cdot 18!+1$ , but also $19|9^9\cdot 9!+1$.
II. For odd $n$, if $2n+1$ is prime, then it seems either
$(2n+1)|n^n\cdot n!+1$, as for $$n=5, 9, 11, 15, 21, 33, 35, 65, 75, 81, 83, 89,...$$
or $(2n+1)|n^n\cdot n!-1$, as for $$n=1, 3, 23, 29, 39, 41, 51, 63, 69, 95, 99, ...$$Thus for odd $n$ and prime $p=2n+1$, either $p|n^n\cdot n!+1$, or $p|n^n\cdot n!-1$.
III. If $p=n+1$ is universally sufficient, and yet not necessary, for $p|n^n\cdot n!+1$, it is perhaps not surprising, as the posted counterexample indicates, that neither is $p=n+1$ necessary for $p^2|n^n\cdot n!+1$. Still, one wonders why $n^n\cdot n!+1$ is divisible by $p^2$ for so few $n$, but divisible by $p$ for so many.
