A Game of 2
Submissions: 1107   Accuracy:


  Difficulty: Easy   Marks: 2

One day Karan and Arjun were playing a game. The game always starts with Karan as he is the younger brother among the two and thereafter play alternate turns. They always try to show their power to each other but this time they decided to show it with numbers. Both of them like the number 2. So they decided to play it with 2. First they decide a random number n and then they take some actions on the number n. If they found that number is not a power of 2, then they reduce the number by the largest power of 2 less than the number and if they found that the number is a power of 2, they simply reduces the number by the half. Then they perform the same operations with the new number generated until the number n becomes 1 and further no one can play the game. The last person to make a valid move will win the game.

The first line contains an integer T, the number of test cases. Then T test cases follow. Each test case will contain an integer n, denoting the starting number.

For each test case in a new line print the winner of the game.



For first test case 6 is not a power of 2 Karan takes the largest power of 2 less than 6 which is 4 in this case and reduces the n to 2. Now 2 is a power of 2 therefore Arjun reduces it to half and number becomes 1 and afterwards Karan cannot make a move and therefore lose the game.


** For More Input/Output Examples Use 'Expected Output' option **

Contributor: vaibhav garg
Author: justrelax

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.