Facebook Pixel

Divisor Game

Problem Statement

Two players take turns playing a number game. Starting with a number N on the board:

  1. The current player chooses a number x where 0 < x < N and x divides N evenly
  2. Replace N with N - x
  3. The player who cannot make a move loses

Player 1 moves first. Return true if Player 1 wins with optimal play, false otherwise.

N = 4

Player 1 picks 1: N becomes 3
Player 2 picks 1: N becomes 2
Player 1 picks 1: N becomes 1
Player 2 cannot move → Player 1 wins

Answer: true
Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro