You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the winner. You will take the first turn to remove the stones.
Both of you are very clever and have optimal strategies for the game. Write a function to determine whether you can win the game given the number of stones in the heap.
你在和朋友玩拈(尼姆)遊戲:有一堆石頭在桌上,每次你的回合可以拿走一到三顆石頭。誰拿走最後一顆石頭的就是贏家。你先手。
你們兩個都很聰明,一定會採取最佳策略。請寫一個程式,給予開場的石頭數量,判斷你是能夠贏得這場遊戲。
4
的倍數的時候,你會輸,反之則贏。LeetCode
C++