Let P(x) be a non-zero polynomial and d=degP. We shall prove that f(P(x))=Cd, for some constant C, furthermore f(0)=0. It is easy to check that such a function properly works.
Letting (P(x),Q(x))=(P(x),1), (b,P(x)) in the second equation as well as (P(x),Q(x))=(a,1) in the first equation for some non-zero constants a,b we conclude that f(a)=0 and f(bP(x))=f(P(x)). Letting (P(x),Q(x))=(bx,bx+1) to obtain f(x+b)=f(x+1) for all b=0. Let c,d be two arbitrary real numbers such that cd=0 it follows that
f(x+cd)=f(c(x+cd))=f(cx+d)=f(x+1).
Finally, letting (P(x),Q(x))=(cx,x−c1) for some c=0,1 in the first equation yields
f(x)=f(cx)=f(cx+1−c1)=f(x+1).
Hence, if P(x) is a linear polynomial then f(P(x))=f(x+1), i.e., a constant function, say C. We then finish our proof based on the induction on the degree of polynomial. The base is true for d=0,1. Assume that the statement holds true for all polynomials of degree less than d. Choose a non-zero rational number r such that P(r)=0. Letting R(x)=P(r)rP(x+r) it follows that R(0)=r. Hence, R(x)=r+xS(x), for some polynomial S(x) of degree d−1. Putting (P(x),Q(x))=(R(x),x−r) in the first equation yielding
f(R(x)−r)=f(xS(x))=f(x)+f(S(x))=f(R(x−r))=f(P(r)rP(x))=f(P(x)).
According to the induction hypothesis f(S(x))=C(d−1) and f(x)=C. Hence,
f(P(x))=Cd.