Note that k=1 is an answer since we can choose a permutation with a2i−1=2i, a2i=2i−1.
Now we take k>1, denote S0,S1,S2,…,Sk−1 as the subsets of {1,2,3,…,1000} and all elements of Si are congruent to i modulo k. We have:
- The number of elements of St is mt=⌈k1000−t⌉.
- Since ai=i±k and ai≡i(modk), two numbers ai and i belong to same subset.
Denote t=x1<x2<…<xmt as elements of St then they form an arithmetic progression with formula xi=t+(i−1)k for 1≤i≤mt.
Put yi=axi for 1≤i≤mt then ∣yi−xi∣=∣axi−xi∣=k which implies that y1<y2<…<ymt is a permutation of x1<x2<…<xmt.
Set ri=kxi−t+1, si=kyi−t+1 for 1≤i≤mt then ri=i and ∣si−i∣=1.
We have
i=1∑mt∣ri−si∣+i=1∑mt∣ri+si∣=2i=1∑mtmax{ri,si}
so mt+2∑i=1mtri=2∑i=1mtmax{ri,si} and mt is even. By the similar definition for i=0,1,…,k−1, we have m0≤m1≤…≤mk−1 are all even and
m0−mk−1=[k1000]−[k1000−(k−1)]≤1.
Hence, m0,m1,…,mk−1 are all equal and even. This can happen when k∣1000 and k1000 is an even number. It is easy to check that we can construct such a permutation satisfying these k.
Therefore, k is a divisor of 500.