Suppose
n=pqr, where
p<q are primes and
r>1.
Then, p≤2,q≥3 and r≥2, not necessarily a prime.
Thus, we have
n−2≥n−p=pqr−p≥5p>p
n−2≥n−q=q(pr−1)≥3q>q
n−2≥n−pr=pr(q−1)≥2pr>pr
n−2≥n−qr=qr(p−1)≥qr
Observe that p,q,pr,qr are all distinct.
Hence, there product divides (n−2) !.
Thus, n2=p2q2r2 devides (n−2)!
In this case, n=pq where p,q are distinct primes n=pk for some p.
Case 1. Suppose n=pq for some primes p,q where 2<p<q.
Then, p≥3 and q≥5 .
In this case,
n−2>n−p=p(q−1)≥4p
n−2>n−q=q(p−1)≥2q
Thus, p,q,2p,2q are all distinct numbers in the set {1, 2, 3, ...., n - 2}.
We see that n2=p2q2 divides (n−2)!.
We conclude that n=2q for some prime numbers q≥3.
Note that, n−2=2q−2<2q in this case so that n2 does not divide (n−2)!
Case 2. Suppose n=kp for some prime p.
We observe that p,2p,3p,...,(pk−1−1)p all lie in the set {1, 2, 3, ...,n−2 }.
If pk−1−1≥2k, then there are at least 2k multiples of p in the set {1, 2, 3, ..., n−2 }.
Hence, n2=p2k divides (n−2)!.
Thus, pk−1−1<2k.
If k≥5, then pk−1−1≥2k−1−1≥2k, which maybe proved by an easy induction.
Hence, k≤4.
If k=1, we get n=p, a prime.
If k=2, then p−1<4 so that p=2 or 3; we get
n=22=4 or n=32=9.
For k=3, we have p2−1<6 giving p=2; n=23=8 in this case.
Finally , k=4 gives p3−1<8.
Again, p=2 and n=24=16.
However, n2=28 divides 14! and hence it is not a solution.
Thus, n=2,2p for some prime p or n=8,9.
It is easy to verify that these satisfy the conditions of the problem.