# Solve for $n$, with factorial.

If $\sqrt{n! + 23}$ is an integer, then $n=$?

I started: $k \in \mathbb{N}$ and:

$$k = \sqrt{n! + 23}$$

It follows, $n! = k^2 - 23$

$\Gamma(n+1) = k^2 - 23$ but that doesnt help?

• If $n\geq23^2$ then $n!+23$ is multiple of $23$ but not of $23^2$. This bounds a little the solutions to $1\leq n\leq23^2$.
– Pp..
Feb 3 '15 at 17:18
• For $n>4$ $n!+23$ is $=3$ mod $4$. But squares leave remainders $0,1$ mod $4$. So, we only need to try with $n=1,2,3$.
– Pp..
Feb 3 '15 at 17:22
• For $n=2$ we get $\sqrt{2!+23}=\sqrt{25}=5$. While $\sqrt{1!+23}$ and $\sqrt{3!+23}=\sqrt{29}$ are not integers.
– Pp..
Feb 3 '15 at 17:23

For $n\geq4$ we have that $n!+23$ leaves remainder $3$ mod $4$. But squares of integers can only leave remainder $0$ or $1$ mod $4$.

Therefore we only need to check $n=1,2,3$.

We get that only $n=2$ gives $$\sqrt{2!+23}=\sqrt{25}=5.$$

• This is a good answer! But which $\pmod{n}$ should I use? Feb 3 '15 at 17:33
• @ama $4$? Consider remainders after division by $4$.
– Pp..
Feb 3 '15 at 17:34
• That is what I ask. Why did you choose $4$ specifically? Feb 3 '15 at 17:37
• @ama Having seen many problems in which squares and remainders mod $4$ are relevant, is the main reason. As you can see, the path to getting the answer is not necessarily straight. In the comments above you can see that I first noticed that $23$ is a prime, and therefore for $n\geq23^2$ you don't get enough factors $23$ to get a square. Another idea that passed my mind was Wilson theorem because in the case $n=23$ we get $23!+23=23((23-1)!+1)$ and by Wilson's theorem $(23-1)!+1$ is multiple of $23$. These ideas got discarded when I noticed $23=20+3=4\cdot5+3$.
– Pp..
Feb 3 '15 at 17:43

If $n\geq 46$, then $23$ divides $n!+23$ but $23^2$ does not divide $n!+23$, hence $n!+23$ is not a square. This gives that we have only a finite number of cases to check.

• Very clever argument!
– hbp
Dec 4 '15 at 0:12

We are looking for $n$ such that $n!+23$ is square. For $n\geq 5$ the last digit of $n!$ is $0$ or in modular arithmetic $n!\equiv 0\pmod{10}$. Therefore $n!+23\equiv 3 \pmod{10}$. Therefore it cannot be a square because a square $\pmod{10}$ can only be $\{1,4,9,6,5\}$. Remains to check the cases $\lt 5$ and only $n=2$ works¤