4. Determine all functions $f: \mathbb{N} \rightarrow \mathbb{N}$ that satisfy the following two conditions:

(i) $f(n!)=f(n)$ for every natural number $n$;

(ii) $m-n$ divides $f(m)-f(n)$ for all distinct natural numbers $m$ and $n$.

(Saudi Arabia)
4. From $f(1)=f(1)!$ and $f(2)=f(2)!$ it follows that $f(1), f(2) \in \{1,2\}$.

Assume $f(3)=3$. If we define inductively $n_{0}=3$ and $n_{i+1}=n_{i}!$ for $i \geqslant 0$, then $f\left(n_{i}\right)=n_{i}$ for all $i$. Consider an arbitrary natural number $m$. Since the difference $m-n_{i}$ divides $f(m)-f\left(n_{i}\right)$, it also divides $f(m)-m$ for every $i$, so $f(m)-m$ has infinitely many divisors; hence $f(m)=m$ for every $m$.

Now let $f(3) \neq 3$. From $4=3!-2 \mid f(3)!-f(2)=f(3)!-2$ it follows that $4 \nmid f(3)!$, so $f(3) \in \{1,2\}$. Moreover, $n!-3$ divides $f(n)!-f(3)$ for every $n \geqslant 4$, so $3 \nmid f(n)!$, which implies $f(n) \in \{1,2\}$ for all $n$. It is easy to see that in this case $f$ must be constant.

Therefore, the only solutions are the functions $f \equiv 1, f \equiv 2$ and $f(x)=x$.