4. Find all functions $f: \mathbb{R}^{+} \rightarrow \mathbb{R}^{+}$ such that for all positive real numbers $x$ and $y$,

$$
f(x)+f(y)=(f(f(x))+f(f(y))) f(x y)
$$

and such that only finitely many images in the codomain have more than one (i.e., at least 2) preimages.

## First Grade - B Category
4. Let $f(1)=c$. Substituting $x=y=1$ into the given equation, we get $2c = 2f(c)c$, from which it follows that $f(c)=1$. Substituting only $y=1$, we get $f(x) + c = (f(f(x)) + 1)f(x)$, i.e., $f(f(x)) = \frac{f(x) + c}{f(x)} - 1 = \frac{c}{f(x)}$. Let $A$ be the set of all images of the function $f$. From the previous equality, it follows that for all $x \in A$, we have $f(x) = \frac{c}{x}$. The converse is also true: if for some $x$ it holds that $f(x) = \frac{c}{x}$, then we have $f\left(\frac{c}{x}\right) = f(f(x)) = \frac{c}{f(x)} = x$, i.e., $x \in A$. Thus, we have that $x \in A$ if and only if $\frac{c}{x} \in A$. Now, substituting into the initial equation $f(f(x)) = \frac{c}{f(x)}$ (and similarly for $y$), we get $f(x) + f(y) = \left(\frac{c}{f(x)} + \frac{c}{f(y)}\right) f(xy) = \frac{c(f(y) + f(x))}{f(x) f(y)} f(xy)$, from which it follows that $f(xy) = \frac{f(x) f(y)}{c}$. Now, if we take $x, y \in A$ (recall that then $f(x) = \frac{c}{x}$ and $f(y) = \frac{c}{y}$), from the previous equality we get $f(xy) = \frac{c^2}{cxy} = \frac{c}{xy}$, from which it follows that $\frac{c}{xy} \in A$, and then $xy \in A$.

We know that $c \in A$. If this is the only element of the set $A$, then $f$ is a constant function $f(x) \equiv c$, and substituting this into the initial equation, we get $2c = 2c \cdot c$, from which it follows that $c = 1$, i.e., one solution is $f(x) \equiv 1$.

Now, assume that $f$ is not a constant function. Then there exists at least one real number $z$ different from 1 in the set $A$. Then it follows that all numbers of the form $z^k, k \in \mathbb{N}$, are in the set $A$, which means that the set $A$ contains infinitely many different real numbers. First, let's prove that in this case $f$ is an injection. Assume the contrary: for some different $x$ and $y$, we have $f(x) = f(y)$. Let $w_1, w_2, w_3, \ldots$ be a sequence of real numbers such that the values $f(w_1), f(w_2), f(w_3), \ldots$ are all different. Then we have $f(w_k x) = \frac{f(w_k) f(x)}{c} = \frac{f(w_k) f(y)}{c} = f(w_k y)$; thus, for every $k$, the value $\frac{f(w_k) f(x)}{c}$ is in the set of images of the function $f$ but has at least two preimages (these are $w_k x$ and $w_k y$), which contradicts the condition of the problem. It follows that $f$ must be an injection (if it is not a constant function). Now we have $f\left(\frac{c}{f(x)}\right) = f(f(f(x))) = \frac{c}{f(f(x))} = f(x)$, and it follows that $\frac{c}{f(x)} = x$, and thus $f(x) = \frac{c}{x}$ for all $x$. Checking shows that this solution also satisfies the initial equation (for any value of $c$).

Thus, all solutions to the given functional equation are: $f(x) \equiv 1$ and $f(x) = \frac{c}{x}$ for any $c \in \mathbb{R}^+$.

## First Grade - B Category