# Number Theory: $p!+p=n^2$, $p$ = prime

Find all prime numbers $p$ such that $p!+p$ is a perfect square.

I think the only ones are when $p!+p=p^2$, i.e. $p\in \{2,3\}$.

Any ideas at all?

• every prime factor is twice in a perfect square you can use this fact and that p ist the biggest prim factor in p! – Manuel G Mar 27 '15 at 10:09
• Wilson's theorem gives that $p^2\mid p!+p$. If $q$ is a prime less than $p$, then $q\nmid p!+p$ because $q\mid p!$, but $q\nmid p$. – Michael Burr Mar 27 '15 at 10:34
• Just as a note $5!+5=5^3$ – Mark Bennet Mar 27 '15 at 11:07

First let $p>3$ and now for all primes $q<p$ we've $(\frac{p}{q})=1$. Now as $(\frac{q}{p})(\frac{p}{q})=(-1)^{\frac{p-1}{2}\frac{q-1}{2}}$ and $p \equiv 1 (\mod 4)$ so, $(\frac{q}{p})=1$ for all primes $q<p$ and that implies $(\frac{n}{p})=1$ for all $n<p$ but that's the contradiction since there is $\frac{p-1}{2}$ non residues. So $p=3$
Note that for a small prime $q\lt p$ we have that $r=(p-1)!+1\equiv 1 \bmod q$
We have, by Wilson's Theorem that $pr=p^2s$ for some integer $s$. Now we are given that $s$ is a square and we know that $r$ is a quadratic residue $\bmod q$ (it is equivalent to the square $1$).
Since residue $\times$ residue = residue, and non-residue $\times$ residue = non-residue, it follows that $p$ must be a quadratic residue $\bmod q$ for every prime $q\lt p$.