Divisor Game - Problem
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 integer
xwith0 < x < nandn % x == 0 - Replacing the number
non the chalkboard withn - x
If a player cannot make a move, they lose the game.
Return true if Alice wins the game, assuming both players play optimally.
Input & Output
Example 1 — Alice Loses (Odd)
$
Input:
n = 3
›
Output:
false
💡 Note:
Alice can only choose x=1, giving Bob n=2. Bob then chooses x=1, giving Alice n=1. Alice cannot move and loses.
Example 2 — Alice Wins (Even)
$
Input:
n = 4
›
Output:
true
💡 Note:
Alice chooses x=1, giving Bob n=3. Bob must choose x=1, giving Alice n=2. Alice chooses x=1, giving Bob n=1. Bob cannot move and loses.
Example 3 — Base Case
$
Input:
n = 2
›
Output:
true
💡 Note:
Alice chooses x=1 (only valid divisor), giving Bob n=1. Bob has no valid moves and loses.
Constraints
- 1 ≤ n ≤ 1000
Visualization
Tap to expand
Understanding the Visualization
1
Input
Starting number n on chalkboard
2
Game Play
Players alternate choosing divisors and subtracting
3
Winner
Alice wins if n is even, loses if n is odd
Key Takeaway
🎯 Key Insight: Alice wins if and only if the starting number is even
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code