A XOR operation

3.7

14 votes
Bit manipulation, Bit Manipulation, Basics of Bit Manipulation, Basic Programming
Problem

You are given a set S of distinct positive integers of size n (n is always even). Print the minimum positive integer k that is greater than 0 such that after replacing each element e of the set S with ek, set S remains the same.

Print -1 if there is no such k.

Note: It is guaranteed that n2 is odd.

Input format

  • The first line contains a single integer t (1t100) denoting the number of test cases.
  • The first line of each test case contains a single integer n (2n1e5) denoting the number of elements in the set.
  • The second line of each test case contains n integers e (1e1e9).

Output format

Print t lines each containing a single line that contains k.

Sample Input
1
6
5 6 9 10 13 14
Sample Output
3
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

By performing the XOR of k with each element we get the given set S

5⊕3=6

6⊕3=5

13⊕3=14

14⊕3=13

9⊕3=10

10⊕3=9

S' = {6,5,14,13,10,9} which is same as S={5,6,13,14,9,10}

Editor Image

?