#MTH000000022. Loại bỏ lá bài II (Throwing Cards Away II)
Loại bỏ lá bài II (Throwing Cards Away II)
Throwing Cards Away II
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
An ordered deck contains cards numbered from to , with card on top and card on the bottom.
While at least two cards remain, perform these operations in order:
- discard the top card;
- move the new top card to the bottom of the deck.
Find the last remaining card.
Input
One positive integer .
Output
Print the number on the last remaining card.
Subtasks
- Subtask 1 (20%): .
- Subtask 2 (30%): .
- Subtask 3 (50%): Full constraints: .
Examples
Input
7
Output
6
Explanation
Start with 1 2 3 4 5 6 7. The deck changes as follows:
- Discard
1, then move2to the bottom:3 4 5 6 7 2. - Discard
3, then move4to the bottom:5 6 7 2 4. - Discard
5, then move6to the bottom:7 2 4 6. - Discard
7, then move2to the bottom:4 6 2. - Discard
4, then move6to the bottom:2 6. - Discard
2, leaving only card6.
Therefore the program prints 6.