Problems > Take-Away Game

Take-Away Game

Difficulty: 1300 2000 ms 128 MB

math games

A pile holds N stones. Players alternate removing between 1 and K stones; whoever takes the last stone wins. Both play perfectly — who wins?

Input: one line with two integers N and K.

Output: FIRST or SECOND.

Constraints:

  • 1 ≤ N ≤ 1018
  • 1 ≤ K ≤ 109

Sample Tests

Input 1
10 3
Output 1
FIRST
Input 2
8 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.