Coin Game
Time limit2sMemory limit512 MB
Given n coin piles and a fixed k, players alternately remove a coin or split an even pile into k equal halves; decide the winner under optimal play.
- Level
Hard8 of 10
- Topics
- Game theory, Math, Greedy
- Solved
- No attempts yet
Problem
Kevin and Nicky are playing a new game. The rules are as follows.
- The game starts with piles of coins, and pile holds coins.
- The two players take turns, and Kevin moves first.
- On a turn a player picks one nonempty pile and performs exactly one of these two moves.
- Remove one coin from that pile.
- This move is available only when the pile holds an even number of coins. Write that number as . Replace the pile with piles that hold coins each.
The player who takes the last coin wins. Given , , and the values , print who wins when both players play optimally.
Input
The first line contains and . (, )
The second line contains positive integers separated by spaces. ()
Output
Print the name of the winner, either Kevin or Nicky.