f(n)=n2.
It is given that
(f(m)+f(n)−mn)∣(mf(m)+nf(n)).(1)
1. Take m=n=1 in (1), we have 2f(1)−1∣2f(1)⇒f(1)=1.
2. Let p be a prime number, and take (m,n)=(p,1), then we have f(p)−1+p∣pf(p)+1, which is
f(p)−p+1∣pf(p)+1−p(f(p)−p+1)=p2−p+1.
- If f(p)−p+1=p2−p+1, then f(p)=p2.
- If f(p)−p+1=p2−p+1, since p2−p+1 is odd, we must have 3(f(p)−p+1)≤(p2−p+1), that is
f(p)≤31(p2+2p−2)(2)
Now, take m=n=p in (1), we have 2f(p)−p2∣2pf(p). This implies
2f(p)−p2∣2pf(p)−p(2f(p)−p2)=p3.
But by (2) and by the fact that f(p)≥1, we have
−p2<2f(p)−p2≤32(p2+2p−2)−p2<−p
for p≥7. This contradicts to the fact that 2f(p)−p2 is a factor of p3.
Hence, we have proved that f(p)=p2 for all prime p≥7.
3. Now, fixed n, and take prime p≥7. Set m=p in (2), and we have
==p2+f(n)−pnf(p)+f(n)−pn∣pf(p)+nf(n)−n(f(p)+f(n)−pn)pf(p)−nf(p)+pn2=p(p2−pn+n2).
However, we can take p sufficiently large such that p∤f(n), which means (p,p2−pn+f(n))=1, so p2−pn+f(n)∤p2−pn+n2. Hence,
p2−pn+f(n)∤p2−pn+n2+(p2−pn+f(n))=n2−f(n).
Since this must hold for all p, but p2−pn+f(n)→∞, the only possibility is n2−f(n)=0, that is f(n)=n2.
4. The rest is to check that f(n)=n2 indeed satisfies the conditions.