It is given that
f(a)+f(b)−ab∣af(a)+bf(b).(3)
Taking a=b=1 in (3), 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 a=p and b=1 in (3), 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), i.e.
f(p)≤31(p2+2p−2).(4)
Taking a=b=p in (3), we have 2f(p)−p2∣2pf(p). This implies
2f(p)−p2∣2pf(p)−p(2f(p)−p2)=p3.
By (4) 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 a be a fixed positive integer. Choose a sufficiently large prime p. Consider b=p in (3). We obtain
f(a)+p2−pa∣af(a)+p3=a(f(a)+p2−pa)+p3−p2a+pa2,
i.e.
f(a)+p2−pa∣p(p2−pa+a2).
As p is sufficiently large and a is fixed, p cannot divide f(a), and so numbers f(a)+p2−pa and p are relatively prime. It follows that
f(a)+p2−pa∣p2−pa+a2=(f(a)+p2−pa)+a2−f(a),
i.e.
f(a)+p2−pa∣a2−f(a).
Note that a2−f(a) is fixed while f(a)+p2−pa is chosen to be sufficiently large. Therefore, we must have a2−f(a)=0, so that f(a)=a2 for any positive integer a.
Finally, we check that when f(a)=a2 for any positive integer a, then
f(a)+f(b)−ab=a2+b2−ab
and
af(a)+bf(b)=a3+b3=(a+b)(a2+b2−ab).
The latter expression is divisible by the former for any positive integers a and b. This shows that f(a)=a2 is the only solution.