Kitty and Katty have plastic blocks. They label the blocks with sequential numbers from to and begin playing a game in turns, with Kitty always taking the first turn. The game's rules are as follows:
- For each turn, the player removes blocks, and , from the set. They calculate , write the result on a new block, and insert the new block into the set.
- The game ends when only block is left. The winner is determined by the value written on the final block, :
- If , then Kitty wins.
- If , then Katty wins.
- If , then the player who moved last wins.
Recall that is the Modulo Operation.
Given the value of , can you find and print the name of the winner? Assume that both play optimally.
Note: The selection order for and matters, as sometimes . The diagram below shows an initial set of blocks where . If and , then the newly inserted block is labeled ; alternatively, if and , the newly inserted block is labeled .
Input Format
The first line contains a single positive integer, (the number of test cases or games).
The subsequent lines each contain an integer, (the number of blocks for that test case).
The subsequent lines each contain an integer, (the number of blocks for that test case).
Constraints
Output Format
For each test case, print the name of the winner (i.e.: either Kitty or Katty) on a new line.
Editorial
Special Case
Let us first deal with the special case. When ``, there is only one element in the array, and nobody can make a move. Kitty wins since the remainder is ``.
Solution
For any arbitary ``, imagine the game is being played. Eventually, the game will come to a situation when there are exactly two elements in the array, `` and ``. Since the game is decided by the final value modulo ``, we can say that `` and `` and play with these two numbers instead. It will not affect the game state.
Now, if ``, then this player can simply replace `` with ``. The final value will be ``, and this player will win.
If they are not equal, then this player will still win. This player wins because she can choose the value of her move where either `` or `` is left as the final value.
Suppose `` and ``. If this player wants to have the final value as ``, then she will just choose `` and `` and replace them with ``. If she wants ``, then she will chose `` and `` and replace them with ``.
So, the player who makes the last move always wins. If `` is even, then Kitty wins, otherwise Katty wins.
Code
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
if(n==1)
{
cout<<"Kitty"<<endl;
continue;
}
if(n%2==1)
{
cout<<"Katty"<<endl;
}
else cout<<"Kitty"<<endl;
}
return 0;
}
This comment has been removed by the author.
ReplyDelete