4. Let a function $f: \mathbb{N} \rightarrow \mathbb{N}_{0}$ be defined as follows:
1) $f(1)=0$,
2) $f(p)=1$, for every prime number $p$,
3) $f(a b)=a f(b)+b f(a)$, for all $a, b \in \mathbb{N}$.

Determine all numbers $n \in \mathbb{N}$ such that $f(n)=n$.
Solution. By induction on the number of factors $k \geq 2$ in the representation of a natural number $n$ as a product of natural numbers in the form $n=a_{1} a_{2} \ldots a_{k}$, we will prove that

$$
f(n)=f\left(a_{1} a_{2} \ldots a_{k}\right)=\frac{n}{a_{1}} f\left(a_{1}\right)+\frac{n}{a_{2}} f\left(a_{2}\right)+\ldots+\frac{n}{a_{k}} f\left(a_{k}\right)
$$

Let $n=a b$. Then from 3) it follows that

$$
f(n)=f(a b)=b f(a)+a f(b)=\frac{a b}{a} f(a)+\frac{a b}{b} f(b)=\frac{n}{a} f(a)+\frac{n}{b} f(b) .
$$

which means that formula (1) holds for $k=2$. Suppose that formula (1) holds for some $k \geq 2$. Then, if the number $n$ is written as a product of $k+1$ natural numbers, i.e., $n=a_{1} a_{2} \ldots a_{k} a_{k+1}$, from the inductive hypothesis and from 3) it follows that

$$
\begin{aligned}
f(n) & =f\left(a_{1} a_{2} \ldots a_{k-1} a_{k} a_{k+1}\right)=\frac{n}{a_{1}} f\left(a_{1}\right)+\frac{n}{a_{2}} f\left(a_{2}\right)+\ldots+\frac{n}{a_{k-1}} f\left(a_{k-1}\right)+\frac{n}{a_{k} a_{k+1}} f\left(a_{k} a_{k+1}\right) \\
& =\frac{n}{a_{1}} f\left(a_{1}\right)+\frac{n}{a_{2}} f\left(a_{2}\right)+\ldots+\frac{n}{a_{k-1}} f\left(a_{k-1}\right)+\frac{n}{a_{k} a_{k+1}}\left(a_{k+1} f\left(a_{k}\right)+a_{k} f\left(a_{k+1}\right)\right) \\
& =\frac{n}{a_{1}} f\left(a_{1}\right)+\frac{n}{a_{2}} f\left(a_{2}\right)+\ldots+\frac{n}{a_{k-1}} f\left(a_{k-1}\right)+\frac{n}{a_{k}} f\left(a_{k}\right)+\frac{n}{a_{k+1}} f\left(a_{k+1}\right)
\end{aligned}
$$

i.e., formula (1) holds for $k+1$, and by the principle of mathematical induction, it follows that it holds for every $k \in \mathbb{N}$.

Let $n \in \mathbb{N}$ and $n=p_{1}^{a_{1}} p_{1}^{a_{2}} \ldots p_{k}^{a_{k}}$ be the canonical representation of $n$. Then from formula (1) and condition 2) it follows that

$$
f(n)=f\left(p_{1}^{a_{1}} p_{1}^{a_{2}} \ldots p_{k}^{a_{k}}\right)=\sum_{i=1}^{k} a_{i} \cdot \frac{n}{p_{i}} f\left(p_{i}\right)=\sum_{i=1}^{k} a_{i} \cdot \frac{n}{p_{i}} \cdot 1=n \sum_{i=1}^{k} \frac{a_{i}}{p_{i}}
$$

Now, if $f(n)=n$, then from (2) it follows that $\sum_{i=1}^{k} \frac{a_{i}}{p_{i}}=1$. If $k>1$, then it is clear that $0<\frac{a_{i}}{p_{i}}<1$ for every $i=1,2, \ldots, k$. But, this means that $p_{i} \nmid a_{i}$ for every $i=1,2, \ldots, k$. We have $\frac{a_{1}}{p_{1}}=1-\sum_{i=2}^{k} \frac{a_{i}}{p_{i}}=\frac{N}{p_{2} p_{3} \ldots p_{k}}$, for some $N \in \mathbb{N}$, so $a_{1} p_{2} p_{3} \ldots p_{k}=p_{1} N$, which is a contradiction because the right side of the last equation is divisible by $p_{1}$, while the left side is not divisible by $p_{1}$. From the obtained contradiction, it follows that $k=1$, which means that $\frac{a}{p}=1$, i.e., $a=p$. But, this means that the only numbers for which $f(n)=n$ are numbers of the form $n=p^{p}$, where $p$ is a prime number.