Divisor Game

James and Oliver take turns playing a game, with James 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 where 1 <= N <= 1000.
  • 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 James wins the game, assuming both players play optimally.

Example 1:

Input: 2
Output: true

James chooses 1, and Oliver has no more moves.

Example 2:

Input: 3
Output: false

James chooses 1, and Oliver chooses 1, and James has no more moves.

Try it yourself



Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

1  >>> a = [1, 2, 3]
2  >>> a[-1]
3  3

Get premium for instant access to all content and solutions