Nim Game 3
InterviewTime limit1sMemory limit512 MB
Given Nim pile sizes, count how many first moves (choosing a pile and removing stones) leave the opponent in a losing position.
- Level
Medium5 of 10
- Topics
- Game theory, Bit manipulation, Math, Greedy
- Solved
- No attempts yet
Problem
Gusagwa and CubeLover are playing a game of Nim. Nim uses piles of stones stacked upward, and each pile contains at least one stone. The two players take turns. On your turn, you choose one pile that has stones and remove one or more stones from that pile. The player who removes the last stone from all piles wins.
Gusagwa moves first. Assuming both players play optimally, find the number of moves Gusagwa can make on the first turn that let him win the game.
Input
The first line gives the number of stone piles ().
The second line gives the number of stones in each pile ().
Output
Print the number of moves Gusagwa can make on the first turn that let him win the game.