#P2054. Card Riffle Shuffle
Card Riffle Shuffle
Card Riffle Shuffle
In this problem, you are given a deck of N cards (where N is even) numbered from 1 to N in increasing order. A single riffle shuffle is defined as follows: split the deck into two equal parts, the top half and the bottom half. Then, form a new deck by taking cards alternately from the bottom and top halves. Specifically, take the first card of the bottom half as the new deck's first card, then the first card of the top half as the new deck's second card, then the second card of the bottom half, followed by the second card of the top half, and so on until all cards are used.
For example, if N = 6 and the original deck is \(1,2,3,4,5,6\), after one shuffle the deck becomes \(4,1,5,2,6,3\). After a second shuffle, it becomes \(2,4,6,1,3,5\).
The game is played as follows: given the deck of N cards (with faces 1 to N), perform M consecutive shuffles. The challenge is to determine the number on the card at the L-th position (1-indexed) after all shuffles. Help Little L secure victory by computing this value!
inputFormat
The input consists of a single line containing three space-separated integers: N, M, and L.
- N: the number of cards (an even integer).
- M: the number of shuffles.
- L: the 1-indexed position to query after shuffling.
You may assume that the input values are such that the answer fits in a standard integer type.
outputFormat
Output a single integer representing the number on the card at the L-th position after performing M shuffles.
sample
6 1 1
4