Find all the functions $f: \mathbb{N} \to \mathbb{N} $ such that $(m+f(n))(n+f(m))$ is a perfect square for all $m,n$ Let $N$ be the set of natural number. Find all functions $f: \mathbb N \to \mathbb N$ , such that the number $(m+f(n))(n+f(m))$ is perfect square for all natural numbers $m$ and $n$.

I was unable to solve this problem so I need a solution to it, I know that the condition that $(m+f(n))(n+f(m))$ is a perfect square would imply that if $n = m$ then $f(n) = f(m)$ but how would that help me in solving the problem?
When we have two numbers $a, b$ whose product is a perfect square, we can trace two observations on them:
Obs. 1: If $a$ is a square then $b$ is a square too.
Obs. 2: If $p$ is a prime and $p^k||a$ (short for &quot;$p^k|a$ but $p^{k+1}\not|a$&quot;) and $p^l||b$, then $k+l$ is even; in particular, if $k$ is odd, then $l$ is odd (and it implies an obvious but useful thing: odd numbers can't be zero).

Obviously, constant functions aren't solutions for our problem. And by simple verification $f(x)=x+C$ with C natural works. We want to show there are no others.
Lemma 1: for every prime $p$ and integers $a,b$  such that $p|a-b$, there exists a constant $k$ such that there are odd numbers $\alpha, \beta$ such that $p^\alpha||a+k$ and $p^\beta||b+k$.
Proof:
Let $z$ the smallest natural number such that $p|a+z$. Obviously, $p|b+z$ too. Now some case-by-case analysis:

$p^2|a+z$ and $p^2|b+z$. That way, $a+z+p \equiv p \not\equiv 0 \pmod{p^2}$ but $a+z+p \equiv 0 \pmod{p}$, and we can choose $k=z+p$, and $\alpha=1,\beta=1$.

$p^2 \not |a+z$. More cases!

$p^2 \not| b+z$. Well, just add $p^3$ to both! It will give us $\alpha=1,\beta=1$.
$p^3 \not| b+z$. Now we can choose $k=C \cdot p^3-b-z$ with $C$ a very large non-multiple of $p$ (in order to $k&gt;0$). That way, we have $a+z+k=Cp^3+a+z$ is multiple of $p$ but not $p^2$, and $b+z+k=Cp^3$ multiple of $p^3$ but not $p^4$. That way we can take $\alpha=1, \beta=3$.
$p^4 \not| b+z$. Just add $p^5$, it will give us $\alpha=1, \beta=3$.
$p^4 | b+z$. Just add $p^3$, it will give us $\alpha=1, \beta=3$.



Now we need to show that $f(n+1)-f(n)=1$ for any $n$.
If there was a prime $p$ such that $p|f(n+1)-f(n)$, then by the Lemma abiove we can choose $k$ such that $p^\alpha||k+f(n+1)$ and $p^\beta||k+f(n)$ with $\alpha, \beta$ odd.
But $(k+f(n+1)) \cdot (f(k)+n+1)$ is a perfect square. By the Obs. 2, $p|(f(k)+n+1)$. The same way, $p|(f(k)+n)$ too, and then $p|1$, contradiction.
Then $p$ does not exist, and so $f(n+1)=f(n)+1$ or $f(n+1)=f(n)-1$
If there was an $N$ such that $f(N+1)=f(N)-1$, then $(N+f(N+1)) \cdot (N+1+f(N)) = (N+f(N)-1) \cdot (N+f(N)+1) = (N+f(N))^2-1$ would be a perfect square, and it can occur if and only if $N+f(N)=0$, or $f(N)=0, N=0$.
Then we can split it in two cases:

$f(0) = 0$. Then $f(N+1) = f(N)-1$ only if $N=0$. That way, $f(1)=0-1&lt;0$, contradiction.

$f(0) \not = 0$. Then $f(N+1) \not= f(N)-1$ for every $N$, and then $f(N+1) = f(N)+1$ for every $N$.


Problem solved! By naive induction, $f(n)=n+C$ with $C=f(1)-1$.
There are only two ways that $(n+f(m))(m+f(n))$ can be a perfect square.


$(n+f(m))$, $(m+f(n))$ are perfect squares for every natural number $n,m$. 
$(n+f(m))=A=(m+f(n))$ in which case $(n+f(n))(m+f(n))=A^2$


The first way cannot happen, because if $(n+f(m))$ is a perfect square $$((n+1)+f(m))=(n+f(m))+1$$ isn't. You cannot add one to a perfect square and get another perfect square here is a list to convince you:

$$1,4,9,16,25,36,49,...$$

So the only way $(n+f(m))(m+f(n))$ is a perfect number is if$$n+f(m)=m+f(n)$$  Set $m=n-1$ then we get 

$$n+f(n-1)=(n-1)+f(n)$$

solving for $f(n)$ gives us
$$f(n)=f(n-1)+1$$
Notice that

$$f(n)=f(n-1)+1=f(n-2)+2=...=f(1)+(n-1)$$

What this means is given any natural number $c$. $$f(n)=c+(n-1)$$ is a solution.
Here is a check:

$$(m+f(n))(n+f(m))=(m+[c+(n-1)])(n+[c+(m-1)])=(m+n+c-1)^2$$