#C6700. Klara's Winning Strategy
Klara's Winning Strategy
Klara's Winning Strategy
Two players, Klara and John, play a game with a pile of N stones. The rules are as follows:
- On each turn, the current player can remove exactly 1, 3, or 4 stones from the pile.
- Klara always makes the first move.
- If a player cannot make a move (i.e. when the pile is empty), that player loses.
Assuming both players play optimally, determine which player has a winning strategy for a given initial number of stones. Output "Klara" if the starting player can force a win, otherwise output "John".
The state recurrence can be expressed in LaTeX as follows:
\(dp[0] = \text{False}\) (losing state), and for \(i \ge 1\):
\(dp[i] = \lnot dp[i-1] \lor \lnot dp[i-3] \lor \lnot dp[i-4]\), where conditions for \(dp[i-k]\) are applied only if \(i-k \ge 0\).
inputFormat
The first line contains an integer T (\(1 \le T \le 10^5\)), the number of test cases. Each of the following T lines contains a single integer N (\(0 \le N \le 10^6\)), representing the initial number of stones.
outputFormat
For each test case, output a single line containing either "Klara" if the first player has a winning strategy, or "John" otherwise.
## sample4
1
2
3
10
Klara
John
Klara
Klara
</p>