All problems
1030EasyMathDynamic ProgrammingBrainteaserGame TheoryImpartial Game

Who Wins the Shrinking Counter

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1025Divisor Game

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A counter starts at n. Two players take turns and the first player goes first.

On a turn a player picks a whole number below the counter and above nothing that divides the counter evenly, then lowers the counter by that amount. A player with no legal pick loses.

Both play as well as they can. Return whether the first player wins.

Examples

Example 1

Input
n = 6
Output
true

Six is even, so the first player lowers it by one and hands over five. Five is odd, so whatever the other player picks leaves an even counter, and the first player keeps handing odd counters back until the other player faces a counter of one.

Example 2

Input
n = 1
Output
false

There is no legal pick at all, since a pick has to sit below the counter and above nothing, so the first player loses at once.

Example 3

Input
n = 999
Output
false

An odd counter has only odd divisors, so the first player must hand over an even counter and the other player takes the winning side.

Constraints

  • 1 <= n <= 1000

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def divisor_game(n: int) -> bool:
Java
public boolean divisorGame(int n)
September 7
Apply