Problems > The Divisor Game

The Divisor Game

Difficulty: 1200 2000 ms 128 MB

math games

Starting with N, players alternate replacing N with N − d where d is any proper divisor of N (1 ≤ d < N). A player who cannot move (N = 1) loses. Who wins?

Input: one integer N.

Output: FIRST or SECOND.

Constraints:

  • 1 ≤ N ≤ 1018

Sample Tests

Input 1
2
Output 1
FIRST
Input 2
3
Output 2
SECOND

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.