#CF2240C. Nim 游戏就是异或游戏 / C. Nim Game Is XOR Game
Nim 游戏就是异或游戏 / C. Nim Game Is XOR Game
C. Nim Game Is XOR Game
Source: Codeforces 2240C
Contest: Codeforces Round 1105 (Div. 2)
Time limit: 2 seconds
Memory limit: 256 megabytes
Statement
Alice and Bob are playing a game with an array consisting of non-negative integers. Alice goes first.
In each turn, the current player must choose an array of non-negative integers that satisfies the following conditions:
- for all ;
- (i.e. the array does not consist entirely of zeros);
- , where denotes the bitwise XOR operation.
After choosing the array , the player updates the array by performing for all .
The player who cannot perform such an operation loses the game.
Determine the number of valid choices for the array that Alice can make on her first turn to guarantee a win, assuming both players play optimally. Since this number may be large, output the answer modulo .
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer () — the length of the array .
The second line of each test case contains integers () — the contents of the array
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output the number of valid choices for the array that Alice can make on her first turn to guarantee a win modulo .
Note
In the first test case, Alice must choose an array of length . The conditions require , , and . It is impossible to satisfy and simultaneously. Thus, Alice has no valid moves and loses immediately. The answer is .
In the second test case, . Alice must choose . The condition implies that . Since and , and the array cannot consist entirely of zeros, the only valid choice is . If Alice chooses , the array updates to . Now it is Bob's turn. Similar to Alice's situation, Bob must choose such that . Since , he is forced to pick , which means . Since a valid move must have , Bob has no valid moves and loses. Therefore, is a winning move for Alice, and the answer is .
Examples
5
1
1
2
1 2
5
1 4 5 2 6
1
1073741823
3
1 2 3
0
1
3
0
1