Let $k,n\ge 1$ be relatively prime integers. All positive integers not greater than $k+n$ are written in some order on the blackboard. We can swap two numbers that differ by $k$ or $n$ as many times as we want. Prove that it is possible to obtain the order $1,2,\dots,k+n-1, k+n$.
Problem
Source: Polish MO Finals 2014
Tags: contests, number theory, relatively prime
29.07.2016 22:54
Nice problem We will build a series of swaps out of the ones we are given. Let $a= \text{max} (k,n), b =\min (k,n)$. Consider two numbers which differ by $a-b$: Let them be $x, x+a-b$. It's clear that one of $x-b, x+a$ is in the range $[1, k+n]$, WLOG suppose $x-b$ is in the range. We can switch the pair $(x,x-b)$, then switch the pair $(x-b,x+a-b)$, and then switch the positions of $(x,x-b)$ again. The end result of this sequence of moves is that the pair $(x,x+a-b)$ has switched positions. Therefore if we can swap numbers differing by $a$ and $b$, we can swap numbers differing by $a-b$. Now it's clear what we should do: We can replace $(a,b)$ with a new tuple $(a', b') = (\text{max} (b,a-b), \min (b,a-b))$. It's clear that $(a',b')$ has the same property as $(a,b)$: we can swap any numbers differing by $a'$ or $b'$. But as we keep replacing the tuple, $(a,b)$ is following precisely the Euclidean Algorithm; therefore, eventually the process terminates when $a=b=1$, since we assumed $\gcd (k,n)=1$. At this point, we know that we can build a series of moves which swaps any two numbers differing by $1$ but does not change the positions of other numbers. Then it's easy to place the numbers in increasing order with the following algorithm: Suppose the first $m$ numbers are now in increasing order for $m\ge 0$. Let the $m+1$th number be $x$, so clearly $x>m+1$. We can swap the following pairs: $(x, x-1), (x-1,x-2), ... (m+2,m+1)$. When we perform this switch, the number $m+1$ will go to the original position of $x$, which is position $m+1$. Therefore, we have now sorted the first $m+1$ numbers in increasing order. We can repeat the process until $m=k+n$, at which point the whole list is sorted.
30.07.2016 08:42
Another nice solution: Consider a graph with vertices $V_i, 1\le i\le n + k$, and connect two of them if and only if their indices differ by $n$ or $k$. We can easily see it is connected for the following reason: All vertices connect back to one of $V_1, V_2, \ldots, V_n$. Now, $\{1, 1 + k, 1 + 2k, \ldots, 1 + (n - 1)k\}$ forms a complete residue system modulo $k$, and hence it is easy to see that by shifting from $i$ up by $k$ multiple times (and shifting backwards by $n$ whenever we hit an integer from $[n + 1, n + k]$) we hit all of $V_1, \ldots, V_n$ in our path. So everything is connected. Now take a spanning tree (i.e. delete one edge from the lone cycle that exists). Then, at every turn, we match up a leaf up with its number by proper swaps and then delete it. This works, and is more general than above (although Euclid's Lemma is nice).
07.11.2016 16:30
By Bezout, we have that there exist positive integers $x,y$ such that $kx-ny=1$ or $ny-kx=1$. Suppose wlog we are in the first case, i.e. $kx-ny=1$. Construct the following sequence: $x_1=1=kx-ny$ and if $x_n=k\alpha-n\beta$, then $x_{n+1} \in \{ k(\alpha+1)-n\beta,\ k\alpha-n (\beta+1)\}$ with $1\le x_{n+1}\le k+n$. It is easy to see that $x_{n+1}$ is thus uniquely defined. Note that if $x_i=ks-nt$, then $s+t=x+y+i-1$. I claim that for $i\le k+n,\ x_i\ne x_j$ for any $j<i$. If $x_i=ka-nb=kc-nd=x_j$, from $(k,n)$ we get that $a=c+n\alpha$ and $b=d+k\alpha$, whence $x+y+i-1=a+b\ge c+d+k+n=x+y+j-1+k+n$, contradiction. Thereby, $x_1,...,x_{k+n}$ is a permutation of $1,2,...,k+n$ in which $x_{i+1}$ can commute with $x_i$ and $x_{i-1}$. The numbers are initially in some order $x_{\sigma(1)},...\ ,x_{\sigma(k+n)}$ and we wish to permute them in an order $x_{\tau(1)},...\ ,x_{\tau(k+n)}$ such that $x_{\tau(i)}=i$. One can prove that $(S_m,\circ)$ is generated by the set of transpositions $\{ (1\ 2),(2\ 3),...,(m-1\ m)\}$ by using that any permutation can be written as the product of some transpositions,$(k\ l)=(1 k) (1\ l)(1\ k)$ combined with $(1\ k+1)=(1\ k)(k\ k+1)(1\ k)$ and induction. Thus, we can apply some transpositions in order to obtain $\sigma^{-1} \tau$, which means that we can get $\tau$ from $\sigma$ after some switches.