We consider the degree of polynomial P:
Case 1: If degP=0 then P(x)≡c for some c∈Z, the given condition becomes S(c)=c which holds if and only if 1≤c≤9.
Case 2: If degP=1. We notice that S(m+n)≤S(m)+S(n) for all positive integers m,n and the equality occurs when there is no carry in the addition m+n. Let P(x)=ax+b for a,b∈Z and a=0. Since S(P(n))=P(S(n)) for n≥2017 then a must be positive. The given condition becomes S(an+b)=aS(n)+b for n≥2017. Putting n=2025 and n=2020, we get
S(2025a+b)−S(2020a+b)=(aS(2025)+b)−(aS(2020)+b)=5a.
We also have
S(2025a+b)=S((2020a+b)+5a)≤S(2020a+b)+S(5a).
These imply that S(5a)≥5a, as a≥1, this holds only when a=1. Then we have S(n+1+b)−S(n+b)=S(n+1)−S(n).
1. If b>0 then choose n such that n+1+b=10k for some k big enough then all digits of n+b are 9 then the left hand side is 1−9k. Also note that n is a positive integer less than 10k−1, then S(n)<9k, which means S(n+1)−S(n)≥1−(9k−1)=2−9k>1−9k, a contradiction.
2. If b<0, similarly, we also come to a contradiction.
Thus b=0 and P(x)=x, which is trivially satisfied.
Case 3: If degP=d≥2 then the leading term of P is adnd with ad=0, then similarly we have ad>0. Choose n=10k−1 for some k∈Z+ big enough, then S(P(n))=P(9k).
Since P(9k) grows approximately as (9k)d while S(P(n)) grows approximately as a constant multiple of k, the given equality cannot hold for sufficiently large k since d≥2.
In conclusion, P(x)=c for some c∈{1,2,3,…,9} or P(x)=x, ∀x. □