Nim Game 101


Recently when I was doing a problem on Codeforces, I learned a new concept of game theory called a nim game. The game consists of two players, where there are piles with some coins, and players will take turn to remove some numbers of coins from any pile. The winner will be the last one who can move. The question is who will be the winner if they both play optimally.

Interestingly, we can solve this by calculating the XOR sum of the numbers of coins from every pile. If the sum is zero, the first player to move will be lose.

Oops have't finished yet, will write soon...

int x = 0;
for (int i = 0; i < n; i++) {
    cout << "hi";
}