A deck holds an even number 2n of cards a1,a2,…,a2n, all distinct (a1<a2<⋯<a2n). At the start the deck is perfectly sorted: the first card is a1, the second card is a2, and so on until the last card, which is a2n.
A dealer then repeats a shuffle made of two steps.
- Split the deck into two halves.
- Interleave the cards of the two halves. If the card order at the start of step 1 is x1,x2,…,x2n, then after step 2 the order becomes xn+1,x1,xn+2,x2,…,x2n,xn.
Given the number of cards in the deck, write a program that determines how many times this shuffle must be repeated for the deck to return to its original sorted order.