1025. Divisor Game

Alice and Bob take turns playing a game, with Alice starting first.

Initially, there is a number N on the chalkboard. On each player’s turn, that player makes a move consisting of:

  • Choosing any x with 0 < x < N and N % x == 0.
  • Replacing the number N on the chalkboard with N - x.

Also, if a player cannot make a move, they lose the game.

Return True if and only if Alice wins the game, assuming both players play optimally.

爱丽丝和鲍勃轮流玩游戏,爱丽丝首先出发。

最初,黑板上有一个数字N. 在每个玩家的回合中,该玩家进行以下操作:

  • 选择0 <x <N且N%x == 0的任何x。

  • 用N - x替换黑板上的数字N.

    此外,如果玩家无法移动,他们将失去游戏。

当且仅当Alice赢得比赛时才返回True,假设两个玩家都达到最佳状态。

Example 1:

Input: 2
Output: true
Explanation: Alice chooses 1, and Bob has no more moves.

Example 2:

Input: 3
Output: false
Explanation: Alice chooses 1, Bob chooses 1, and Alice has no more moves.

网上思路

打赏一个呗

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦