# Square does not divide factorial

Find all natural numbers $n$ such that $n^2$ does not divide $(n - 2)!$

My thoughts are if by Wilson's theorem $(p - 1)!$ is not divisible by $p$ and $\gcd (p, p - 1) = 1$ then $n = p$ is done but I am not being able to prove it for composite numbers I. e. $n = pqr$ form.

Any help will be appreciated.

Answer: All numbers that are primes, or twice a prime, or among $1$, $8$, $9$.

Proof: Clearly, $n=1$ does not work ($(n-2)!$ is not even defined). If $n=8$, we check directly that $8^2\nmid 6!$. If $n=9$, we check directly that $9^2\nmid 7!$.

If $n=p$ or $n=2p$ with a prime $p$, at most one of the factors defining $(n-2)!$ is a multiple of $p$ (and not of $p^2$), hence $n^2\nmid (n-2)!$.

If $n=2^k$ with $k>3$, we see the factors $2^{k-1}$, $2^{k-2}$, $6$, $12$ and so $n^2\mid (n-2)!$.

In all other cases, we can write $n=ap$ with $p$ an odd prime and $a\ge3$.

If $a=3$, we can assume $p>3$ and find the distinct numbers $p$, $2p$, $3$, $6$ among the factors and thus have $n!\mid (n-2)!$.

If $a\ge 4$, the four numbers $p$, $2p$, $a$, $2a$ are all $n-2$. If they are pairwise different, this shows $n^2\mid (n-2)!$. However it may happen that $a=p$ or $a=2p$, i.e., $n=p^2$ or $n=2p^2$ with $p\ge 5$. But then we find $p$, $2p$, $3p$, $4p$ among the factors, and so again $n^2\mid 4p^4\mid (n-2)!$. $\square$