All problems
Divisor Game
Problem
Given n, two players alternate choosing a divisor x of n with 0 < x < n and subtract it from n; the player who cannot move loses. Return True if the first player wins.
The first player wins exactly when n is even and greater than 1, because choosing 1 forces an odd number onto the opponent. For n = 1 there is no move and the first player loses.
Hint
Every odd n can only be reduced to an even number by the only odd divisor, 1.
Test cases
case 1
in: [2]
expected: true
case 2
in: [3]
expected: false
case 3
in: [4]
expected: true
case 4
in: [1]
expected: false
case 5
in: [9]
expected: false
case 6
in: [10]
expected: true
Starter codePython
def divisor_game(n):
# Your code here
pass6 test cases · run your code against them in the editor