#1025
Divisor Game
pupil · 340 · lc easy +22 · verified · 71.6% accepted · 2,423 likes · top 81%
Description
Alice and Bob alternate turns (Alice first), maintaining a number n on a board. On each turn, the current player picks any divisor x of n with 0 < x < n, replacing n with n - x. A player who cannot move loses.
Return true if Alice wins when both players play optimally.
Example 1:
Input: n = 2
Output: true
Explanation: Alice chooses 1, and Bob has no more moves.
Example 2:
Input: n = 3
Output: false
Explanation: Alice chooses 1, Bob chooses 1, and Alice has no more moves.
Code
1
2
3