09 Sept 2026Go / Python / TypeScriptEasy

Divisor Game

Determine whether the first player can force a win in the divisor subtraction game.

An even starting value always moves to an odd one, while every legal move from an odd value reaches an even one; therefore the first player wins exactly for even n.

complexity

O(1) time and O(1) space.

solution files

  • Go divisor-game/solution.go
  • Python divisor-game/solution.py
  • TypeScript divisor-game/solution.ts

Solution files

Godivisor-game/solution.go
package main

func divisorGame(n int) bool { return n%2 == 0 }
Pythondivisor-game/solution.py
class Solution:
    def divisorGame(self, n: int) -> bool:
        return n % class="syntax-number">2 == class="syntax-number">0
TypeScriptdivisor-game/solution.ts
function divisorGame(n: number): boolean {
  return n % class="syntax-number">2 === class="syntax-number">0;
}