For k=1, S(k)=1. For k>1, note that for a positive integer a<k relatively prime to k the number k−a is also relatively prime to k. Hence the summands in the sum S(k) can be paired and each pair has sum k. The number of positive integers relatively prime to k (and less than k) is φ(k), so
S(k)=2kφ(k).
Let q be the largest prime factor of m, and let 2=p1<p2<⋯<ps=q be consecutive prime numbers. Then m=p1a1…psas (where some of ai are 0). We will construct a number x of the form x=p1b1…psbs satisfying the condition of the problem. Note that
2S(x)=xφ(x)=p1b1…psbs⋅p1b1−1(p1−1)…psbs−1(ps−1)=p12b1−1(p1−1)…ps2bs−1(ps−1).
Also, for every i≤s all prime divisors of pi−1 are among p1,…,ps, so we choose c1,…,cs such that (p1−1)…(ps−1)=p1c1…pscs, i.e.
2S(x)=p12b1+c1−1…ps2bs+cs−1.
The number x satisfies the condition of the problem if and only if 2bi+ci−1 is divisible by n and bi≥ai, for all i∈{1,…,s}.
Since n is odd, its multiples alternate in being even and odd, so for every i we can choose a large enough ki∈N such that kin≡ci−1(mod2) and
bi=2kin−ci+1≥ai.
Then 2S(x)=p12b1+c1−1…ps2bs+cs−1=(p1k1…psks)n, which shows that x satisfies the condition of the problem.