Let n=kmd+1. We will construct the desired splitting in the following way. To determine which of the subsets each number x∈{1;2;…n} belongs to, let us write x−1 in the form:
x−1=cmd+1+x0+x1m+x2m2+⋯+xdmd,
where c≥0 is an integer, xi∈{0;1;…m−1}, i=0,…,d, i.e. we write the remainder of x−1 divided by md+1 in base m numeral system. We include the number x to subset Aj, j∈{1;2;…m} if x0+x1+x2+⋯+xd≡j(modm). Let us show that such splitting satisfies the condition. Clearly, it is enough to prove our statement for polynomials of the form P(x)=xt, t=0,…,d.
We have
S(Aj)=c=0∑k−1j∑(cmd+1+x0+x1m+x2m2+⋯+xdmd)t,
where ∑j denotes the sum over all tuples x0,…,xd of numbers from the set {0;1;…m−1} such that x0+x1+x2+⋯+xd≡j(modm). Let us show that the inner sum does not depend on j. Denoting z=1+cmd+1, we can transform it by expanding the brackets:
j∑(cmd+1+x0+x1m+x2m2+⋯+xdmd)t=d∑u!t0!t1!…td!t!zumt1+2t2+⋯+dtdj∑x0t0x1t1…xdtd,
where ∑d denotes the sum over all tuples of non-negative integers u,t0,…,td such that u+t0+⋯+td=t. Since t0+⋯+td≤t<d+1, there is at least one number among t0,…,td which equals zero. Suppose that t0=0, then
j∑x0t0x1t1…xdtd=j∑x1t1…xdtd=x1,…,xd=0∑m−1x1t1…xdtd,
because for any tuple x1,…,xd of numbers from {0;1;…m−1} there is a unique number x0∈{0;1;…m−1} for which x0+x1+x2+⋯+xd≡j(modm). The last sum is clearly independent of j, which is what we wanted to prove.