f(x) can be any polynomial of the form
pap(px)+ap−1(p−1x)+ap−2(p−2x)+⋯+a1(1x)+a0,
where a0,a1,…,ap are arbitrary integers with ap=0.
Note that we can always write
f(x)=cp(px)+cp−1(p−1x)+⋯+c1(1x)+c0
for some rational coefficients c0,c1,…,cp, since (px),(p−1x),…,(0x) have different degrees. By putting x=0, we get c0=f(0)∈Z. By putting x=1, we get c1+c0=f(1)∈Z, and hence c1∈Z. Similarly, by putting x=2,3,…,p, we find that all cj's are integers. Conversely, if all cj's are integers, it is obvious that f(m)∈Z for any m∈Z.
Now, putting x=p+1 and using (kp+1)=(kp)+(k−1p), we obtain
f(p+1)−f(1)=k=0∑pck(kp+1)−(c1+c0)=k=1∑pck[(kp)+(k−1p)]−c1.
Since p∣(rp) whenever 1≤r≤p−1, we have
f(p+1)−f(1)≡cp(modp).
Therefore, p∣f(p+1)−f(1) if and only if p∣cp. This shows f(x) can be any polynomial of the form mentioned at the beginning.