Binary Knockout
Time limit1sMemory limit128 MB
A coin game on a line: each coin may double its position or move one step right; the player unable to move loses. Find the k-th value of n where the second player wins.
- Level
Hard9 of 10
- Topics
- Game theory, Math, Bit manipulation
- Solved
- No attempts yet
Problem
Two players play a game called binary knockout. It is played on a board of fields numbered from to . At the start every field holds exactly one pawn. The players move alternately.
A single move works as follows: pick a pawn on some field and move it to field for any integer , as long as that field exists (that is, ). If the destination field already held a pawn, the two pawns knock each other out and both are removed from the board.
A player who cannot make any move on their turn loses.
The first player moves first and the second player moves second. By choosing the board size carefully, the second player can be given a guaranteed winning strategy; this happens, for example, for boards of size , , and . List every board size on which the second player has a winning strategy in increasing order, and report the -th of them.
Input
The only line of input contains one integer ().
Output
Output a single integer: the -th smallest board size on which the second player has a winning strategy.