TITLE: Find all functions $f: \mathbb N \rightarrow \mathbb N$ such that $f(n!)=f(n)!$
QUESTION [20 upvotes]: Find all functions $f: \mathbb N \rightarrow \mathbb N$ (where $\mathbb N$ is the set of positive integers) such that $f(n!)=f(n)!$ for all positive integers $n$ and such that $m-n$ divides $f(m)-f(n)$ for all distinct positive integers $m,n$.
My work so far:
$f(1!)=f(1)=f(1)!$ and $f(2!)=f(2)=2$. Then $f(1)=1$ or $f(1)=2$ or $f(2)=1$ or $f(2)=2$.
Case 1: $f(1)=f(2)=1$. I proved $f(n) \equiv 1$
Case 2: $f(1)=f(2)=2$. I proved $f(n) \equiv 2$
Case 3: $f(1)=2$ and $f(2)=1$. I proved that this case is impossible.
Case 4: $f(1)=1$ and $f(2)=2$. I need help here.

REPLY [8 votes]: Here is a short proof, motivated by @PatrickStevens' argument. (Here a novel part is Lemma 2, and the other parts are simplification of Patrick's argument.)
Assume that $f(1) = 1$ and $f(2) = 2$.

Lemma 1. $f(3) = 3$.

Proof. $4 \mid (f(6) - 2)$ and $f(6) = f(3)!$ implies that $f(3) = 2$ or $3$. But $2 \mid (f(3) - 1)$ implies that $f(3)$ is odd. Therefore $f(3) = 3$.

Lemma 2. For any $n$, we have $n \mid f(n)$.

Proof. Given $n$, choose $k$ so that $b := 3!^{\circ k} \geq n$, where $!^{\circ k}$ denotes the $k$-fold factorial. Then $n \mid b! = f(b!)$. Hence writing $f(n) - f(b!) = N(n - b!)$ for some integer $N$, we have
$$ f(n) \equiv f(n) - f(b!) = N(n - b!) \equiv 0 \pmod{n}. $$

Lemma 3. $f(n) = n$ for all $n$.

Proof. Assume otherwise and let $n$ be the smallest positive integer satisfying $f(n) \neq n$. (In particular, $n \geq 4$.) By Lemma 2, $f(n) \geq 2n$ and hence $(2n)! \mid f(n)!$. Also, by the minimality of $n$, we have $f(n-1) = n-1$. Then with $N := (n-1)(n-1)!$, we have
$$ (n-1)! = f((n-1)!) - f(n!) + f(n)! \equiv N + 0 \equiv 0 \pmod{N}. $$
This contradicts $N > (n-1)!$. Therefore no such $n$ with $f(n) \neq n$ exists.

Addendum. I guess it would worth it to explain how I come up with Lemma 2. In fact, I made a significant detour. Let $p$ be arbitrary prime. Then with the usual $p$-adic norm, the assumption says that
$$ |f(m) - f(n)|_p \leq |m - n|_p, \quad m, n \in \Bbb{N}. \tag{*} $$
That is, the function $f$ is Lipschitz on the dense subset $\Bbb{N}$ of $\Bbb{Z}_p$. So $f$ uniquely extends to a continuous function $f_p : \Bbb{Z}_p \to \Bbb{Z}_p$ which also satisfies $\text{(*)}$. Now by Lemma 1, we can choose $x_j \in \Bbb{N}$ such that $|x_j|_p \to 0$ and $|f(x_j)|_p \to 0$ as $j \to \infty$. By continuity, this implies that $f_p(0) = 0$. Plugging this to $\text{(*)}$, we have
$$ |f_p(n)|_p \leq |n|_p, \quad n \in \Bbb{Z}_p. $$
Since this is true for all $n \in \Bbb{N}$ and for all prime $p$, this implies $n \mid f(n)$.
Now decoding this analytic proof in terms of congruence gives the proof of Lemma 2.