Easy to see that f(n)≤f(1)n by substituting a=1. By substituting a=nb−f(b) in the inequality for any large enough n, we have
nb∣(nb−f(b))2+bf(nb−f(b))
and hence b∣f(b)2. In particular, for every prime p, f(p)=kpp for some integer 0<kp≤f(1). Therefore, there must be an integer k, such that f(p)=kp for infinitely many prime p. Thus, for infinitely many p,
a+kp∣(a2+pf(a))−a(a+kp)=pf(a)−pka
thus a+kp∣f(a)−ka. Since p can be infinitely large, we must have f(a)=ka.
Substitute b=1 and rearrange to find that
a+f(1)f(a)+f(1)2=f(1)−a+a+f(1)a2+f(a)
is a positive integer and since f(a)≤af(1), follows that a+f(1)f(a)+f(1)2≤f(1), hence for some positive integer k, a+f(1)f(a)+f(1)2=k, i.e., f(n)=kn+f(1)(k−f(1)) for infinitely many n. Fixing an arbitrary a, rearrange the given inequality, we have
a+kn+f(1)(k−f(1))a2+nf(a)
is an integer for infinitely many n. Since
a+kn+f(1)(k−f(1))a2+nf(a)→kf(a)
as n→∞, we have
a+kn+f(1)(k−f(1))a2+nf(a)=kf(a)
for infinitely many n. Thus
kf(a)(a+f(1)(k−f(1)))=a2.(1)
Let X=f(1)(k−f(1)), we have a+X∣a2+(X+a)(X−a)=X2 holds for arbitrary a. Thus X=0, that is, k=f(1). By equation (1), f(a)=ka. □