4. Determine all functions $f: \mathbb{N} \rightarrow \mathbb{N}$ for which

$$
f\left(f(m)^{2}+2 f(n)^{2}\right)=m^{2}+2 n^{2} \quad \text { for all } m, n \in \mathbb{N} \text {. }
$$

(Bulgaria)
4. It is clear that the function $f$ is injective. Define $g(n)=f(n)^{2}$. The given relation for $f$ becomes

$$
g(g(m)+2 g(n))=\left(m^{2}+2 n^{2}\right)^{2}
$$

From the equality $(n+2)^{2}+2(n-1)^{2}=(n-2)^{2}+2(n+1)^{2}$, it follows that $g(n+2)-2 g(n+1)+$ $2 g(n-1)-g(n-2)=0$, i.e., the sequence $(g(n))_{n \in \mathbb{N}}$ satisfies a linear recurrence relation whose general solution is

$$
g(n)=a n^{2}+b n+c+d(-1)^{n}
$$

By substituting (2) into (1) for $m=1$ and rearranging, we get $A n^{4}+B n^{3}+C n^{2}+D n+$ $E \pm F=4 n^{4}+4 n^{2}+1$ for all $n$, where $A=4 a^{3}$ and $B=8 a^{2} b$, from which we obtain $a=1$ and $b=0$. Now (2) becomes $f(n)^{2}=n^{2}+\left(c+d(-1)^{n}\right)$. For $n>|c|+|d|$, we have $n^{2}-n<f(n)^{2}<n^{2}+n$, so it must be that $f(n)=n$, i.e., $c+d(-1)^{n}=0$, which gives us $c=d=0$. Hence, $f(n)=n$ for all $n$.

The function $f(n)=n$ clearly satisfies the condition of the problem.