#P6791. Stone Game with Doubling Limit
Stone Game with Doubling Limit
Stone Game with Doubling Limit
Two players, A and B, play a stone game. Initially, there is a pile of \( n \) stones. Player A moves first, and then the players alternate turns. On A's first move, he may remove at most \( k \) stones (and at least one stone). On every subsequent move, a player may remove at most twice the number of stones removed by the opponent in the previous move. In each move, a player must remove at least one stone.
The twist is that the player who removes the last stone loses the game, and the other player wins. Given two integers \( N \) and \( k \), where \( N \) indicates the upper bound of the number of stones, your task is to determine how many integers \( n \) in the interval \( [1, N] \) yield a winning strategy for player A when the game starts with \( n \) stones and with the first-move removal limit of \( k \).
inputFormat
The input consists of two space-separated integers: N
and k
.
outputFormat
Output a single integer: the number of values of \( n \) in the interval \( [1, N] \) for which player A can force a win.
sample
10 2
8