Root Game
InterviewTime limit1sMemory limit512 MB
For each N, decide who wins the subtraction game where a move subtracts any perfect square from a running total and taking the last square wins.
- Level
Medium5 of 10
- Topics
- Game theory, Dynamic programming, Math, Brute force
- Solved
- No attempts yet
Problem
Koosaga and Cubelover are about to play the root game. The root game uses a single integer, and initially this integer is N.
The two players take turns, and Koosaga moves first. On each turn, a player chooses a perfect square x greater than or equal to 1 and subtracts x from N. The integer may not become negative, and the player who makes it 0 wins the game.
Write a program that determines who wins when both players play optimally.
Input
The first line gives the number of test cases T (1 ≤ T ≤ 105). The next T lines give the test cases, one per line, each containing N (1 ≤ N ≤ 106).
Output
For each test case, print the winner. Print "koosaga" if Koosaga wins, and "cubelover" if Cubelover wins.