Game of Drinks

3.2

14 votes
Problem

Tyrion Lannister is the most intelligent person in the land of Westeros. He and his brother Jaime Lannister like to drink a lot.

Once Tyrion and his brother were drinking in King’s Landing. They decide to play a game in which they take turns. Tyrion always moves first.

In the beginning there is one glass on the table containing x units of wine.

In his move a player picks a glass of wine from the table and pours the entire wine in that glass into n (n ≥ 2) number of empty glasses and puts them on the table. The ith glass contains Ai units of wine such that the following conditions are satisfied:

  • Ai > 0 for all 1 ≤ in.
  • Ai – Ai+1 = 1 for all 1 ≤ in-1.

Both Players play optimally. If a player is unable to move, he loses. Determine the winner of the game.

INPUT:

The first line contains an integer T(1 ≤ T ≤ 10), the number of Test cases.

Then T lines follow. Each line contains an integer x (1 ≤ x ≤ 100000), units of wine in the first glass.

OUTPUT:

For each Test case:

If Tyrion wins print 2 lines. Output “Tyrion Won” in the first line and in the next line output an integer n the minimum number of glasses into which he can pour the wine from the first glass in the first move so as to win the game.

If Jaime wins print a single line, “Jaime Won”.

Sample Input
3
3
4
11
Sample Output
Tyrion Won
2
Jaime Won
Tyrion Won
2
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

In the first example Tyrion has the only choice of pouring the 3 units of wine into two empty glasses containing 2 units and 1 units of wine respectively. Now Jaime cannot choose any glass of wine and meet the above conditions. So, Tyrion wins.

In the second example Tyrion has no valid move.

In the third case, Tyrion can minimize the no. of empty glasses by pouring 11 units into two glasses containing 6 and 5 units respectively. Now Jaime can choose either of the glasses. Let's consider both cases :

If Jaime chooses glass with 6 units, he can pour the wine into three glasses with 3, 2 and 1 units of wine each. Now Tyrion chooses glass with 3 units and breaks it into 2 and 1 units of wine glasses.Now Jaime has no valid move, So he loses.

If Jaime chooses glass with 5 units, he can pour the wine into two glasses with 3 and 2 units of wine each. Now Tyrion chooses glass with 3 units and breaks it into 2 and 1 units of wine glasses.Now Jaime has no valid move, So he loses.

Editor Image

?