It is given that
f(m)+f(n)−mn∣mf(m)+nf(n).(1)
Taking m=n=1 in (1), we have 2f(1)−1∣2f(1). Then 2f(1)−1∣2f(1)−(2f(1)−1)=1 and hence f(1)=1.
Let p⩾7 be a prime. Taking m=p and n=1 in (1), we have f(p)−p+1∣pf(p)+1 and hence
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, as p2−p+1 is an odd positive integer, we have p2−p+1⩾3(f(p)−p+1), that is,
f(p)⩽31(p2+2p−2)(2)
Taking m=n=p in (1), we have 2f(p)−p2∣2pf(p). This implies
2f(p)−p2∣2pf(p)−p(2f(p)−p2)=p3.
By (2) and f(p)⩾1, we get
−p2<2f(p)−p2⩽32(p2+2p−2)−p2<−p
since p⩾7. This contradicts the fact that 2f(p)−p2 is a factor of p3. Thus we have proved that f(p)=p2 for all primes p⩾7.
Let n be a fixed positive integer. Choose a sufficiently large prime p. Consider m=p in (1). We obtain
f(p)+f(n)−pn∣pf(p)+nf(n)−n(f(p)+f(n)−pn)=pf(p)−nf(p)+pn2.
As f(p)=p2, this implies p2−pn+f(n)∣p(p2−pn+n2). As p is sufficiently large and n is fixed, p cannot divide f(n), and so (p,p2−pn+f(n))=1. It follows that p2−pn+f(n)∣p2−pn+n2 and hence
p2−pn+f(n)∣(p2−pn+n2)−(p2−pn+f(n))=n2−f(n).
Note that n2−f(n) is fixed while p2−pn+f(n) is chosen to be sufficiently large. Therefore, we must have n2−f(n)=0 so that f(n)=n2 for any positive integer n.
Finally, we check that when f(n)=n2 for any positive integer n, then
f(m)+f(n)−mn=m2+n2−mn
and
mf(m)+nf(n)=m3+n3=(m+n)(m2+n2−mn).
The latter expression is divisible by the former for any positive integers m,n. This shows f(n)=n2 is the only solution.