The Bit Game
Submissions: 229   Accuracy:

12.25%

  Difficulty: Easy   Marks: 2

Two players, Player 1 and Player 2, are given an integer N to play a game. The rules of the game are as follows :
1. In one turn, a player can swap any 2 bits of N in its binary representation to make a new N.
2. In one turn, a player has to make a number strictly less than N.
3. Player 1 always takes first turn.
4. If a player cannot make a move, he loses.
Assume that both the players play optimally.

Input : 
First line of input contains a single integer T denoting the number of test cases.
The only line of each test case contains an integer N.

Output : 
For each test case, print "1" if Player 1 wins, else print "2" in a new line (without quotes "").

Constraints : 
1 <= T <= 200
1 <= N <= 10^12

Example : 
Input :
 
3
8
1
42
Output : 
1
2
2

Explanation : 
Case 1 : 
N = 8
N = 1000 (binary)
Player 1 swaps the 1st and 4th bit.
1000
N = 0001
Player 2 cannot make a move, so Player 1 wins.

Case 2 : 
N = 1
Player 1 cannot make a move, so Player 2 wins.

Case 3 : 
N = 42
N = 101010 (binary)
Player 1 swaps the 1st and 6th bit.
101010
N = 1011
Player 2 swaps 1st and 2nd bit.
1011
N = 111
Player 1 cannot make a move, so Player 2 wins.

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

Author: goyalanubhav11


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.