description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1.
-----Input-----
The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case.
-----Output-----
For each test case, output a single line containing the number M or -1 as described above.
-----Constraints-----
- 1 ≤ T ≤ 5000
- 1 ≤ N ≤ 230
-----Example-----
Input:
1
3
Output:
1
-----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
|
for _ in range(int(input())):
n = int(input())
if n == 1:
print(2)
elif n + 1 & n == 0:
print(n // 2)
else:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1.
-----Input-----
The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case.
-----Output-----
For each test case, output a single line containing the number M or -1 as described above.
-----Constraints-----
- 1 ≤ T ≤ 5000
- 1 ≤ N ≤ 230
-----Example-----
Input:
1
3
Output:
1
-----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
|
try:
primes = ["1"]
for i in range(2, 31):
primes.append(primes[0] * i)
for _ in range(int(input())):
given = int(input())
if given == 1:
print("2")
continue
x = bin(given)[2:]
if x in primes:
print(int("1" * (len(x) - 1), 2))
else:
print("-1")
except:
pass
|
ASSIGN VAR LIST STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP STRING BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING
|
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1.
-----Input-----
The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case.
-----Output-----
For each test case, output a single line containing the number M or -1 as described above.
-----Constraints-----
- 1 ≤ T ≤ 5000
- 1 ≤ N ≤ 230
-----Example-----
Input:
1
3
Output:
1
-----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
|
def read():
return input().strip()
def readint():
return int(read())
t = readint()
for i in range(0, t):
n = readint()
if n == 1:
print(2)
continue
if n % 2 == 0:
print(-1)
else:
isFound = True
for j in range(0, 32):
if n == (1 << j) - 1:
k = 1 << j - 1
isFound = False
print(str(k - 1))
break
if isFound:
print(-1)
|
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER
|
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1.
-----Input-----
The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case.
-----Output-----
For each test case, output a single line containing the number M or -1 as described above.
-----Constraints-----
- 1 ≤ T ≤ 5000
- 1 ≤ N ≤ 230
-----Example-----
Input:
1
3
Output:
1
-----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
|
for i in range(int(input())):
n = int(input())
t = -1
for j in range(30):
if n == 2**j - 1:
t = j
break
if t == 1:
print(2)
elif t == -1:
print(-1)
else:
print(2 ** (t - 1) - 1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER
|
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1.
-----Input-----
The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case.
-----Output-----
For each test case, output a single line containing the number M or -1 as described above.
-----Constraints-----
- 1 ≤ T ≤ 5000
- 1 ≤ N ≤ 230
-----Example-----
Input:
1
3
Output:
1
-----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
|
a = [
1,
3,
7,
15,
31,
63,
127,
255,
511,
1023,
2047,
4095,
8191,
16383,
32767,
65535,
131071,
262143,
524287,
1048575,
2097151,
4194303,
8388607,
16777215,
33554431,
67108863,
134217727,
268435455,
536870911,
1073741823,
]
t = int(input())
for _ in range(0, t):
n = int(input())
if n == 1:
print("2")
elif n in a:
p = a.index(n) - 1
print(a[p])
else:
print("-1")
|
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING
|
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1.
-----Input-----
The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case.
-----Output-----
For each test case, output a single line containing the number M or -1 as described above.
-----Constraints-----
- 1 ≤ T ≤ 5000
- 1 ≤ N ≤ 230
-----Example-----
Input:
1
3
Output:
1
-----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
|
for _ in range(int(input())):
curr = int(input())
if bin(curr)[2:].count("0") > 0:
print(-1)
else:
print([curr // 2, 2][curr == 1])
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER NUMBER VAR NUMBER
|
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1.
-----Input-----
The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case.
-----Output-----
For each test case, output a single line containing the number M or -1 as described above.
-----Constraints-----
- 1 ≤ T ≤ 5000
- 1 ≤ N ≤ 230
-----Example-----
Input:
1
3
Output:
1
-----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
|
for _ in range(int(input())):
n = int(input())
flag = 0
if n == 1:
print(2)
continue
for i in range(1, 31):
ans = 1 << i
if ans ^ ans - 1 == n:
print(ans - 1)
flag = 1
if flag == 0:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1.
-----Input-----
The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case.
-----Output-----
For each test case, output a single line containing the number M or -1 as described above.
-----Constraints-----
- 1 ≤ T ≤ 5000
- 1 ≤ N ≤ 230
-----Example-----
Input:
1
3
Output:
1
-----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
|
numb = []
for i in range(31):
numb.append(str(2**i - 1))
for _ in range(int(input())):
n = input()
if n == "1":
print(2)
elif n in numb:
print(int(n, 10) // 2)
else:
print(-1)
|
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER
|
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1.
-----Input-----
The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case.
-----Output-----
For each test case, output a single line containing the number M or -1 as described above.
-----Constraints-----
- 1 ≤ T ≤ 5000
- 1 ≤ N ≤ 230
-----Example-----
Input:
1
3
Output:
1
-----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
|
for _ in range(int(input())):
n = int(input())
if n == 1:
print("2")
elif n % 2 == 0:
print(-1)
else:
x = bin(n)[2:].count("0")
if x == 0:
ans = n // 2
print(ans)
else:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1.
-----Input-----
The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case.
-----Output-----
For each test case, output a single line containing the number M or -1 as described above.
-----Constraints-----
- 1 ≤ T ≤ 5000
- 1 ≤ N ≤ 230
-----Example-----
Input:
1
3
Output:
1
-----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
|
for i in range(int(input())):
n = int(input())
if n == 1:
print(2)
elif n % 2 == 0:
print(-1)
else:
m = n
while m > 1:
m = m // 2
if m % 2 == 0:
print(-1)
break
else:
print(n // 2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1.
-----Input-----
The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case.
-----Output-----
For each test case, output a single line containing the number M or -1 as described above.
-----Constraints-----
- 1 ≤ T ≤ 5000
- 1 ≤ N ≤ 230
-----Example-----
Input:
1
3
Output:
1
-----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
|
t = int(input())
for i in range(t):
flag = True
n = int(input())
if n == 1:
print(2)
else:
m = int(n / 2)
if m ^ m + 1 == n:
print(m)
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1.
-----Input-----
The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case.
-----Output-----
For each test case, output a single line containing the number M or -1 as described above.
-----Constraints-----
- 1 ≤ T ≤ 5000
- 1 ≤ N ≤ 230
-----Example-----
Input:
1
3
Output:
1
-----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
|
for _ in range(int(input())):
l = int(input())
if l == 1:
print(2)
continue
t_1 = list(bin(l)[2:])
flag = 0
for i in range(len(t_1) - 1, 0, -1):
if flag == 1 and t_1[i] == "1":
break
if t_1[i] == t_1[i - 1] and t_1[i] == "1":
continue
else:
flag = 1
if flag == 1:
print(-1)
continue
t_2 = t_1.count("1")
t_3 = 2 ** (t_2 - 1) - 1
print(t_3)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR VAR STRING IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1.
-----Input-----
The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case.
-----Output-----
For each test case, output a single line containing the number M or -1 as described above.
-----Constraints-----
- 1 ≤ T ≤ 5000
- 1 ≤ N ≤ 230
-----Example-----
Input:
1
3
Output:
1
-----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
|
d = {(1): 0}
st = 1
prev = 1
while True:
new = st + st + 1
d[new] = prev
prev = new
st = new
if st > 2 * 2**30:
break
for _ in range(int(input())):
n = int(input())
if n == 1:
print(2)
else:
try:
print(d[n])
except:
print(-1)
|
ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
t = int(input())
while t > 0:
t = t - 1
n, k = map(int, input().split())
max = 1 << n
print((max - 1) * (max - 2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
for _ in range(int(input())):
a, b = [int(i) for i in input().split()]
res = pow(2, a) - 1
print(int(res * (res - 1)))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
t = int(input())
for i in range(t):
n, k = map(int, input().split())
a = 2**n - 1
b = 2**n - 2
print(a * b)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
def Binexp(a, n):
ans = 1
while n > 0:
if n & 1:
ans *= a
a *= a
n >>= 1
return ans
def solve():
n, k = map(int, input().split())
ans = (Binexp(2, n) - 1) * (Binexp(2, n) - 2)
return ans
for _ in range(int(input())):
print(solve())
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
t1 = int(input())
for i in range(t1):
n1, k1 = map(int, input().split())
ans = 1
a1 = n1
while a1 != 0:
ans *= 4
a1 -= 1
ans -= ((1 << n1) - 1) * 3
print(ans - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
MOD = 1000000007
t = int(input())
while t > 0:
N, K = map(int, input().split())
max = 1 << N
print((max - 1) * (max - 2))
t -= 1
|
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
for t in range(int(input())):
n, k = list(int(i) for i in input().split())
l = len(bin(k))
l -= 2
if l > n:
print(0)
else:
print(4**n - 3 * 2**n + 2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
def main():
T = int(input())
for _ in range(T):
N, K = map(int, input().split())
print(pow(4, N) - 3 * ((1 << N) - 1) - 1)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR BIN_OP NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
t = int(input())
while t:
n, k = map(int, input().split())
k = n
res = 1
while k:
res *= 4
k -= 1
res -= ((1 << n) - 1) * 3 + 1
print(res)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
for _ in range(int(input())):
n, k = map(int, input().split())
x = pow(2, n) - 1
y = pow(2, n) - 2
print(x * y)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
t = int(input())
for i in range(t):
a, b = map(int, input().split(" "))
if b > 2**a - 1:
print(0)
else:
ans = 4
s = 4
for j in range(a - 1):
ans = ans * 4
s = 2 * s + 2
print(ans - s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
t = int(input())
for i in range(t):
l = list(map(int, input().split()))
n = l[0]
m = 2**n
print((m - 1) * (m - 2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
t = int(input())
for _ in range(t):
n, m = map(int, input().split(" "))
count = 0
r = 2**n
res = (r - 1) * (r - 2)
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
t = int(input())
while t:
n, k = map(int, input().split())
mod = 10**9 + 7
power = pow(2, n, mod)
print((power - 1) * (power - 2))
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
import sys
f = sys.stdin
next(f)
for s in f:
n = int(s.split()[0])
m = 1 << n
print((m << n) - 3 * m + 2)
|
IMPORT ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
t = int(input())
for _ in range(t):
n, x = input().split(" ")
n = int(n)
ans = (2**n - 1) * (2**n - 2)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
t = int(input())
for i in range(0, t):
n, x = map(int, input().split())
k = n
res = 1
while k != 0:
res = res * 4
k = k - 1
res = res - (2**n - 1) * 3
print(res - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
import sys
input = sys.stdin.readline
def xor(n, k):
cnt = 0
nn = n
n = 2**n
print((2**nn - 2) * (n - 1))
def dense(n, s):
cnt = 0
left = 0
right = n - 1
while left <= right:
if s[left] == ")":
cnt += 1
left += 1
continue
if s[right] == "(":
cnt += 1
right -= 1
continue
if s[left] == "(":
left += 1
if s[right] == ")":
right -= 1
print(cnt)
for t in range(int(input())):
n, k = map(int, input().split())
xor(n, k)
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = 2**n
ans = 4**n - 3 * (a - 1) - 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
q = [0] * 21
for _ in range(int(input())):
n, k = map(int, input().split())
x = (1 << n) - 1
print(x * (x - 1))
|
ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
t = int(input())
while t:
n, k = map(int, input().split())
print((pow(2, n) - 1) * (pow(2, n) - 2))
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
def data():
x, y = map(int, input().split())
max = 1 << x
print((max - 1) * (max - 2))
a = int(input())
while a > 0:
a = a - 1
data()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
import sys
input = sys.stdin.readline
M = int(1000000000.0) + 7
def solve():
n, k = map(int, input().split())
return (2**n - 1) * (2**n - 2)
for _ in range(int(input())):
print(solve())
|
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR RETURN BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the parameters mentioned in the statement.
------ Output Format ------
For each test case, output on a new line the number of triplets that satisfy the given conditions.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤N ≤20$
$0 ≤K < 2^{N}$
----- Sample Input 1 ------
3
2 1
3 0
9 100
----- Sample Output 1 ------
6
42
260610
----- explanation 1 ------
Test case $1$: There are $6$ triplets that satisfy the given conditions: $(0, 2, 3)$, $(0, 3, 2)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 0, 2)$ and $(3, 2, 0)$.
Test case $2$: There are $42$ triplets that satisfy the given conditions, some of which are: $(1, 2, 3)$, $(1, 4, 5)$, $(6, 3, 5)$, $(7, 3, 4)$ and so on.
|
t = int(input())
for k in range(t):
n, k = input().split()
n, k = int(n), int(k)
print(4**n - (3 * 2**n - 2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER
|
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).
Each of the following n lines contain two integers li, ri — the arguments for the corresponding query (0 ≤ li ≤ ri ≤ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
|
n = int(input())
for i in range(n):
l, r = map(int, input().split())
l = bin(l)[2:]
r = bin(r)[2:]
while len(l) < len(r):
l = "0" + l
x = [0] * len(l)
for i in range(len(l)):
x[i] = l[i]
if l[i] < r[i]:
ok = True
for j in range(i + 1, len(l)):
x[j] = "1"
if r[j] == "0":
ok = False
if ok:
x[i] = "1"
break
print(int("".join(x), 2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR STRING IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER
|
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).
Each of the following n lines contain two integers li, ri — the arguments for the corresponding query (0 ≤ li ≤ ri ≤ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
|
for i in range(int(input())):
l, r = map(int, input().split())
L = list(bin(l))
R = list(bin(r))
L = L[2:]
R = R[2:]
w = 0
c = 0
L = ["0"] * (len(R) - len(L)) + L
ans = 0
if l == r:
print(l)
continue
for i in range(len(R)):
if L[i] != R[i]:
for j in range(i + 1, len(R)):
if R[j] == "0":
w = 1
if w == 1:
ans = c + 2 ** (len(R) - i - 1) - 1
break
else:
ans = c + 2 ** (len(R) - i) - 1
break
elif L[i] == "1":
c = c + 2 ** (len(R) - i - 1)
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).
Each of the following n lines contain two integers li, ri — the arguments for the corresponding query (0 ≤ li ≤ ri ≤ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
|
from sys import stdin
def parseline(line):
return list(map(int, line.split()))
def round_to_power_of_2(k):
k |= k >> 1
k |= k >> 2
k |= k >> 4
k |= k >> 8
k |= k >> 16
k += 1
return k
def is_power_of_2(k):
return 0 == k & k - 1
lines = list(filter(None, stdin.read().split("\n")))
lines = list(map(parseline, lines))
(n,) = lines[0]
for li, ri in lines[1 : n + 1]:
z = round_to_power_of_2(li ^ ri)
mask = z - 1
if is_power_of_2((ri & mask) + 1):
print(ri)
else:
pos = z >> 1
print(ri ^ pos | pos - 1)
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_DEF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF RETURN NUMBER BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NONE FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER
|
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).
Each of the following n lines contain two integers li, ri — the arguments for the corresponding query (0 ≤ li ≤ ri ≤ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
|
n = int(input())
for k in range(n):
l, r = map(int, input().split())
a = []
for i in range(62):
a.append("0")
lbin = list(bin(l))
lbin = lbin[2:]
ans = l
num = l
for i in range(len(lbin)):
a[61 - i] = lbin[len(lbin) - 1 - i]
blah = 0
for i in range(61, -1, -1):
if a[i] == "0":
a[i] = "1"
num = num + 2 ** (61 - i)
if num <= r:
ans = num
else:
break
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and <image> is maximum possible. If there are multiple such numbers find the smallest of them.
Input
The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).
Each of the following n lines contain two integers li, ri — the arguments for the corresponding query (0 ≤ li ≤ ri ≤ 1018).
Output
For each query print the answer in a separate line.
Examples
Input
3
1 2
2 4
1 10
Output
1
3
7
Note
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
|
import sys
def binary(a):
s = ""
for i in range(64):
if a % 2 == 0:
s += "0"
else:
s += "1"
a //= 2
return s
def dec(s):
resp = 0
for k in s:
resp *= 2
if k == "1":
resp += 1
return resp
def solve(a, b):
x = binary(a)
y = binary(b)
resp = 0
gen = ""
for i in range(len(x) - 1, -1, -1):
if x[i] == y[i]:
gen += x[i]
else:
ones = True
for j in range(i, -1, -1):
if y[j] == "0":
ones = False
break
if ones:
gen += "1"
else:
gen += "0"
for j in range(i - 1, -1, -1):
gen += "1"
break
return dec(gen)
casos = int(input())
for i in range(casos):
line = input()
v = [int(x) for x in line.split()]
print(solve(v[0], v[1]))
|
IMPORT FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR STRING VAR STRING VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR STRING VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR STRING RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
def ans(x):
if x % 2 == 0:
a = x // 2
b = 2 * x - a
if a ^ b == (a + b) / 2:
return a, b
return -1, -1
test_cases = int(input())
while test_cases != 0:
d = int(input())
k1, k2 = ans(d)
if k1 == -1:
print(-1)
else:
print(k1, k2)
test_cases -= 1
|
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR VAR RETURN NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
def generator(x, y):
s = bin(x)[2:]
carry = 0
for i in range(len(s) - 1, -1, -1):
j = len(s) - 1 - i
k1, k2 = x & 1 << j, y & 1 << j
carry += k1 ^ k2
v1 = v2 = 0
for i in range(len(s) - 1, -1, -1):
j = len(s) - 1 - i
if s[i] == "0":
if i >= 1:
_j = len(s) - i
if carry & 1 << _j:
v1 += 1 << j
v2 += 1 << j
else:
v1 += 1 << j
if (v1 + v2) // 2 != x:
return -1, -1
return v1, v2
def main():
t = int(input())
for _ in range(t):
x = int(input())
a, b = generator(x, 2 * x)
if a == -1:
a, b = generator(x, 2 * x + 1)
if a == -1:
print(-1)
else:
print("{} {}".format(a, b))
else:
print("{} {}".format(a, b))
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN NUMBER NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
import sys
input = sys.stdin.readline
out = []
for _ in range(int(input())):
x = int(input())
a = x // 2
b = x ^ a
if a == 2 * x - b:
out.append(f"{a} {b}")
else:
out.append(-1)
for i in out:
print(i)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
for _ in int(input()) * " ":
n = int(input())
x = n // 2
y = 3 * x
if x ^ y == n:
print(x, y)
else:
print(-1)
|
FOR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
def find_pair(x):
if x % 2 == 1:
return -1
a = x + x // 2
b = x - x // 2
if a ^ b == x:
return a, b
else:
return -1
t = int(input())
for _ in range(t):
x = int(input())
ans = find_pair(x)
if type(ans) == int:
print(-1)
else:
print(ans[0], ans[1])
|
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR RETURN VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
t = int(input())
while t:
x = int(input())
a = x + x // 2
b = x // 2
if x % 2 == 1:
print(-1)
elif a ^ b == x:
print(a, b)
else:
print(-1)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
n = int(input())
for i in range(n):
x = int(input())
if x % 2 == 1:
k = (x + 1) // 2
else:
k = x // 2
a = [0] * 33
b = [0] * 33
w = [0] * 33
wk = [0] * 33
for j in range(33):
if x >> j & 1:
w[j] = 1
if k >> j & 1:
wk[j] = 1
flag = False
for j in range(33):
if wk[j] == 1 and w[j] == 1:
flag = True
break
elif w[j] == 1:
a[j] = 1
elif wk[j] == 1:
a[j] = 1
b[j] = 1
if flag == True:
print(-1)
continue
else:
resa = 0
resb = 0
a.reverse()
b.reverse()
for j in range(33):
resa = resa * 2 + a[j]
resb = resb * 2 + b[j]
print(resa, resb)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
for _ in range(int(input())):
n = int(input())
if n % 2 != 0:
print(-1)
continue
if n ^ n // 2 == n // 2 * 3:
print(n // 2, 3 * n // 2)
else:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
def solve():
x = int(input())
a = 2 * x // 4
b = 2 * x // 4 * 3
if 2 * (a ^ b) == a + b and x % 2 != 1:
print(a, b)
else:
print(-1)
t = int(input())
for _ in range(t):
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF BIN_OP NUMBER BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
for i in range(int(input())):
n = int(input())
if n % 2 == 1:
print(-1)
else:
a = n // 2
if a & n == 0:
b = a + n
else:
print(-1)
continue
print(a, b)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
for _ in range(int(input())):
if (p := 3 * (x := int(input())) // 2) ^ (b := x // 2) == x == (p + b) // 2:
print(p, b)
else:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
for _ in range(int(input())):
n = int(input())
if n % 2:
print(-1)
continue
arr = []
while n:
arr.append(n % 2)
n //= 2
arr = arr[::-1]
n = len(arr)
yes = 1
for i in range(n - 1):
if arr[i] == 1 and arr[i + 1] == 1:
yes = 0
print(-1)
break
if yes == 0:
continue
a, b = [(0) for i in range(n)], [(0) for i in range(n)]
for i in range(n - 1):
if arr[i] == 1:
a[i] = 1
a[i + 1] = 1
b[i + 1] = 1
a, b = a[::-1], b[::-1]
a1, b1 = 0, 0
for i in range(n):
a1 += a[i] * 2**i
b1 += b[i] * 2**i
print(str(a1) + " " + str(b1))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
for a in range(int(input())):
n = int(input()) << 1
s = "0" + bin(n)[2:]
c, d = 0, 0
if n % 4 != 0:
print(-1)
else:
n1 = len(s)
for b in range(1, n1):
if s[b] == "1" and s[b - 1] == "1":
print(-1)
break
else:
print(n - (n >> 2), n >> 2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
for i in range(int(input())):
s = int(input())
a = 3 * s // 2
b = s // 2
if s == a ^ b and s - a / 2 - b / 2 == 0.0:
print(a, b)
else:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
for _ in range(int(input())):
a = int(input())
if a % 2:
print(-1)
elif 3 * a // 2 ^ a // 2 == a:
print(3 * a // 2, a // 2)
else:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
t = int(input())
for _ in range(0, t):
x = int(input())
if x % 2 == 1:
print("-1")
else:
a = int(3 * x / 2)
b = int(x / 2)
if a ^ b == x:
print(f"{a} {b}")
else:
print("-1")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR EXPR FUNC_CALL VAR STRING
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
import sys
input = lambda: sys.stdin.readline().strip()
def compute(S, X):
if (S - X) % 2 != 0:
return [-1]
A = (S - X) // 2
a = 0
b = 0
for i in range(64):
Xi = X & 1 << i
Ai = A & 1 << i
if Xi == 0 and Ai == 0:
pass
elif Xi == 0 and Ai > 0:
a = 1 << i | a
b = 1 << i | b
elif Xi > 0 and Ai == 0:
a = 1 << i | a
else:
return [-1]
return [a, b]
def solve():
n = int(input())
a = compute(n * 2, n)
print(*a)
for i in range(int(input())):
solve()
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN LIST NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN LIST NUMBER RETURN LIST VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
t = int(input())
for test in range(t):
x = int(input())
su = x * 2
x1 = "0" + bin(x)[2:]
su1 = bin(su)[2:]
otva = 0
otvb = 0
cur = 1
fl = 1
ls = 0
for i in range(len(x1) - 1, -1, -1):
if int(x1[i]) == abs(int(su1[i]) - ls) == 0:
if x1[i - 1] == su1[i - 1]:
ls = 0
elif su1[i - 1] == 1:
otva += cur
otvb += cur
ls = 1
else:
otva += cur
otvb += cur
ls = 1
elif int(x1[i]) == abs(int(su1[i]) - ls) == 1:
otva += cur
else:
fl = -1
break
cur *= 2
if fl == -1:
print(-1)
else:
print(otva, otvb)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
def solve():
x = int(input())
if x % 2 == 1:
print(-1)
return
rest = x // 2
if x & rest == 0:
print(x + rest, rest)
else:
print(-1)
t = int(input())
for _ in range(t):
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
t = int(input())
for i in range(0, t):
m = int(input())
x = m
l = []
ll = []
while m >= 1:
l.append(m % 2)
m = m // 2
for j in range(1, len(l)):
ll.append(l[j])
ll.append(0)
l
ll
a = 0
b = 0
bl = True
for k in range(0, len(l)):
if l[k] == 1 and ll[k] == 1:
bl = False
break
elif l[k] == 0 and ll[k] == 1:
a = a + pow(2, k) * 1
b = b + pow(2, k) * 1
elif l[k] == 1 and ll[k] == 0:
a = a + pow(2, k) * 1
if x % 2 == 0:
if bl:
print(a, b)
else:
print(-1)
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR VAR EXPR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
def main():
_i = int(input())
for _ in range(_i):
n = int(input().strip("\r\n"))
a1 = ""
a2 = ""
sn = f"{n:b}"
i = 0
fail = False
while i < len(sn):
if sn[i] == "1":
if i == len(sn) - 1 or sn[i + 1] != "0":
fail = True
break
a1 = a1 + "11"
a2 = a2 + "01"
i += 1
else:
a1 = a1 + "0"
a2 = a2 + "0"
i += 1
if fail:
print("-1")
else:
print(int(a1, 2), int(a2, 2))
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
cases = int(input())
def main():
for case in range(cases):
x = int(input())
n = 2 * x
if x % 2:
print(-1)
continue
a = 0
b = 0
wr = bin(x)[:1:-1]
wr += "0"
pow2 = 1
xs = []
for i, d in enumerate(wr):
if d == "1":
a += pow2
else:
xs.append(pow2)
pow2 *= 2
while xs:
p = xs.pop()
if a + b + 2 * p <= n:
a += p
b += p
if a + b == n:
print(a, b)
else:
print(-1)
main()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
t = int(input())
for _ in range(t):
n = int(input())
if n % 2 == 1:
print(-1)
else:
x = n // 2
y = 1
flag = 0
if x == 1:
flag *= 4
for i in range(5):
if y == 0:
y += 1
else:
break
for i in range(35):
if x & y << i:
if n & y << i:
flag = 1
break
if flag == 1:
print(-1)
else:
print(x, 2 * n - x, end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR VAR STRING EXPR FUNC_CALL VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
for _ in range(int(input())):
x = int(input())
if x % 2 == 1:
print(-1)
else:
a = x + x // 2
b = x // 2
if a ^ b == x:
print(a, b)
else:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
t = int(input())
for _ in range(t):
x = int(input())
binary = bin(x)[2:]
a = int(len(binary) * "1", 2)
b = int(binary.replace("0", "_").replace("1", "0").replace("_", "1"), 2)
k = (a + b) // 2
if (a + b) % 2 != 0 or a == 0 or b == 0 or k < x:
print(-1)
continue
diff = k - x
a -= diff
b -= diff
if a <= 0 or b <= 0 or x != (a + b) // 2 or a ^ b != x:
print(-1)
continue
else:
print(a, b)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING STRING STRING STRING STRING NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
def find_ab(x):
a = (x + 1) // 2
b = a ^ x
if (a + b) % 2 == 0 and (a + b) // 2 == x:
return a, b
else:
return -1
for _ in range(int(input())):
ans = find_ab(int(input()))
if ans == -1:
print(-1)
else:
print(ans[0], ans[1])
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
def func():
x = int(input())
if x % 2 == 1:
print(-1)
return
a = 0
v = []
t = x
p = 1
while t != 0:
y = t % 2
t = t // 2
if y == 0:
v.append(p)
else:
a += p
p *= 2
t = x - a // 2
p = 1
b = 0
while t != 0:
y = t % 2
t = t // 2
if y == 1:
if p not in v:
print(-1)
return
b += p
p *= 2
print(a + b, b)
for i in range(int(input())):
func()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
t = int(input())
for i in range(t):
n = int(input())
S = 2 * n
bn = []
tmp = n
while tmp:
bn.append(tmp % 2)
tmp //= 2
bn.reverse()
a = bn[:]
b = [(0) for _ in range(len(bn))]
res = 1
if bn[-1] == 1:
res = 0
else:
for i in range(len(bn) - 1):
if bn[i] and bn[i - 1]:
res = 0
break
if bn[i]:
a[i + 1] = 1
b[i + 1] = 1
if not res:
print(-1)
else:
rA = 0
rB = 0
POW = 1
for i in range(len(bn) - 1, -1, -1):
rA += a[i] * POW
rB += b[i] * POW
POW *= 2
print(rA, rB)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
import sys
def rec(mask, s, x, bit, a, b):
if s == 0 and bit == 0:
return [a, b]
if x & 1:
if s & 1 == 1 + bit & 1:
return rec(mask << 1, s >> 1, x >> 1, bit + 1 >> 1, a | mask, b)
else:
r = None
if bit + 1 + 1 & 1 == s & 1:
r = rec(mask << 1, s >> 1, x >> 1, bit + 1 + 1 >> 1, a | mask, b | mask)
if not r and bit == s & 1:
r = rec(mask << 1, s >> 1, x >> 1, 0, a, b)
if r:
return r
return None
def solve():
x = int(data.readline())
s = x << 1
r = rec(1, s, x, 0, 0, 0)
if r:
print(*r)
else:
print(-1)
data = sys.stdin
total_tests = int(data.readline())
for test in range(total_tests):
solve()
|
IMPORT FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN LIST VAR VAR IF BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR ASSIGN VAR NONE IF BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR RETURN VAR RETURN NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
t = int(input())
for _ in range(t):
x = int(input())
a = x
b = 0
for i in range(32, -1, -1):
if x & 1 << i > 0:
continue
if 2 * x - a - b >= 2 << i:
a += 1 << i
b += 1 << i
if a + b == 2 * x and a ^ b == x:
print(a, b)
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
def check(s, xor):
a2 = (s - xor) // 2
a = 0
b = 0
for i in range(64):
x1 = xor & 1 << i
a1 = a2 & 1 << i
if x1 == 0 and a1 == 0:
pass
elif x1 == 0 and a1 > 0:
a = 1 << i | a
b = 1 << i | b
elif x1 > 0 and a1 == 0:
a = 1 << i | a
else:
return [-1]
if (a + b) % 2 == 0:
data = [a, b]
return data
else:
return [-1]
for _ in range(int(input())):
n = int(input())
m = 2 * n
val = check(m, n)
print(*val)
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN LIST NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR LIST VAR VAR RETURN VAR RETURN LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
for _ in range(int(input())):
n = int(input())
a = 2 * n
if a - n // 2 ^ n // 2 == n:
print(a - n // 2, n // 2)
else:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
def N():
return int(input())
def A():
return [int(x) for x in input().split()]
def S():
return input()
def decimalToBinary(n):
return bin(n).replace("0b", "")
for _ in range(N()):
n = N()
a = []
f = n % 2 == 0
p = 0
b = []
if "codeforces" == 28226329:
print("Tanmay")
for i in range(32, -1, -1):
bit = n >> i & 1
if p == 1 and bit == 1:
f = False
break
if bit == 1:
a.append(1)
b.append(0)
elif p == 1:
a.append(1)
b.append(1)
else:
a.append(0)
b.append(0)
p = bit
if not f:
print(-1)
continue
a1 = b1 = 0
for i in b:
b1 = b1 * 2 + i
for i in a:
a1 = i + a1 * 2
print(a1, b1)
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST IF STRING NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
def main():
n = int(input())
if n % 2:
print(-1)
return
b = bin(n)
b = b[2:]
alt = ["0"] * len(b)
b = list(b)
i = 0
while i < len(b) - 1:
if b[i] == "1":
if b[i + 1] == "1":
print(-1)
return
b[i + 1] = "1"
alt[i + 1] = "1"
i += 1
i += 1
b = "".join(b)
alt = "".join(alt)
a1 = int(b, 2)
a2 = int(alt, 2)
print(a1, a2)
return
for _ in range(int(input())):
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
t = int(input())
for _ in range(t):
n = int(input())
bl = True
if n & 1:
bl = False
a = n // 2
if a & n or not bl:
print(-1)
else:
print(a | n, a)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
import sys
N = int(200000.0 + 5)
sys.setrecursionlimit(N)
def charming():
x = int(input())
if x & 1 == 1:
print(-1)
return
two = list()
for i in range(32):
if x // pow(2, i) & 1:
two.append(i)
a = x + pow(2, two[0] - 1)
b = pow(2, two[0] - 1)
for i in range(1, len(two)):
if two[i] == two[i - 1] + 1:
print(-1)
return
a += pow(2, two[i] - 1)
b += pow(2, two[i] - 1)
if a ^ b == (a + b) // 2:
print(a, b)
else:
print(-1)
for t in range(int(input())):
charming()
|
IMPORT ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
def hkjbklj(x):
if x % 2 == 1:
return -1
s = x // 2
asa = 1
for i in range(1, 30):
asa *= 2
if asa >= x:
asa = i + 1
break
a = [None] * asa
b = [None] * asa
bsb = 1
for i in range(asa):
csc = bsb
bsb *= 2
a[0 - i - 1] = s % bsb // csc
b[0 - i - 1] = s % bsb // csc
s -= s % bsb
c = a[1:] + [0]
for i in range(asa):
if b[i] == 1 and c[i] == 1:
return -1
b[i] += c[i]
dsd = 1
sa = 0
sb = 0
for i in range(asa):
sa += a[asa - i - 1] * dsd
sb += b[asa - i - 1] * dsd
dsd *= 2
return sa, sb
t = int(input())
for i in range(t):
k = hkjbklj(int(input()))
if k == -1:
print(-1)
else:
print(*k)
|
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER RETURN NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
def findab(x):
a = x >> 1
b = x | a
y = (a + b) / 2
if x == y:
print(a, b)
return
print(-1)
return
t = int(input())
for T in range(t):
x = int(input())
findab(x)
|
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
t = int(input().strip())
result = []
for _ in range(t):
x = int(input().strip())
a = x // 2
if 2 * a == x and a & x == 0:
print(a, a + x)
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
t = int(input())
for i in range(0, t):
n = int(input())
def solve(num):
a = 0
b = 0
last = 0
ok = 1
tmp = -1
while num > 0:
w = num & 1
num >>= 1
tmp += 1
if tmp == 0 and w == 1:
ok = 0
break
if w == 1 and last == 1:
ok = 0
break
if w == 1:
a += 1 << tmp
if tmp > 0:
a += 1 << tmp - 1
b += 1 << tmp - 1
last = w
if ok == 1:
print(a, b)
else:
print(-1)
solve(n)
pass
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
def compute(S, X):
A = (S - X) // 2
a = 0
b = 0
for i in range(64):
Xi = X & 1 << i
Ai = A & 1 << i
if Xi == 0 and Ai == 0:
pass
elif Xi == 0 and Ai > 0:
a = 1 << i | a
b = 1 << i | b
elif Xi > 0 and Ai == 0:
a = 1 << i | a
else:
return [-1, -1]
return [a, b]
def solve():
x = int(input())
[a, b] = compute(x * 2, x)
if a ^ b == x and (a + b) / 2 == x:
print(a, b)
else:
print(-1)
return
print("RR", x % 4)
for i in range(x):
if x + i > 2**32:
break
if x - i ^ x + i == x:
print(x - i, x + i)
a = x - i
b = x + i
c = a & b
return
print(f"{a:>08b} {b:>08b} {x:>08b} {c:>08b} ")
print(-1)
for t in range(int(input())):
solve()
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN LIST NUMBER NUMBER RETURN LIST VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN LIST VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN EXPR FUNC_CALL VAR VAR STRING STRING VAR STRING STRING VAR STRING STRING VAR STRING STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
t = int(input())
for i in range(t):
x = int(input())
y = x // 2
a = 0
b = 0
ca = 1
ind = 0
if x % 2 == 1:
print(-1)
continue
while x > 0:
tx = x % 2
ty = y % 2
if tx == 0 and ty == 1:
a += ca
b += ca
elif tx == 1 and ty == 0:
a += ca
elif tx == 1 and ty == 1:
ind = 1
if ind == 1:
break
ca *= 2
x //= 2
y //= 2
if ind == 1:
print(-1)
else:
print(a, b)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
for __ in range(int(input())):
x = int(input())
a, b = x // 2 * 3, x // 2
if a ^ b == x:
print(a, b)
else:
print("-1")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
for n in [*map(int, open(0))][1:]:
b = n >> 1
print(*[b * 3, -1, b][bool(n & 1 or n & b) :: 2])
|
FOR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
for _ in range(int(input())):
n = int(input())
if not n % 2:
n2 = int(n / 2)
if n + n2 ^ n - n2 == n:
print(f"{n + n2} {n - n2}")
continue
else:
print(-1)
else:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
def one():
n = int(input())
s = 1
d = []
while s <= n:
if not n & s:
d.append(s)
s += s
a, b = 0, n
for x in reversed(d):
if a + b + x + x <= n + n:
a += x
b += x
if a + b == n + n:
print(a, b)
else:
print(-1)
t = int(input())
for i in range(t):
one()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
t = int(input())
for test in range(t):
x = int(input())
y = bin(x)
a, b = 0, 0
i = 2
while i < len(y):
if y[i : i + 2] == "10":
a, b = a << 2 | 3, b << 2 | 1
i += 2
elif y[i : i + 1] == "0":
a, b = a << 1, b << 1
i += 1
else:
a, b = None, None
break
if a and b:
print(a, b)
else:
print(-1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NONE NONE IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
t = int(input())
while t:
n = int(input())
if n % 2 != 0:
print(-1)
else:
a = int(3 * n / 2)
b = int(n / 2)
if int((a + b) / 2) == a ^ b:
print(a, b)
else:
print(-1)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER
|
Vlad found two positive numbers $a$ and $b$ ($a,b>0$). He discovered that $a \oplus b = \frac{a + b}{2}$, where $\oplus$ means the bitwise exclusive OR , and division is performed without rounding..
Since it is easier to remember one number than two, Vlad remembered only $a\oplus b$, let's denote this number as $x$. Help him find any suitable $a$ and $b$ or tell him that they do not exist.
-----Input-----
The first line of the input data contains the single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
Each test case is described by a single integer $x$ ($1 \le x \le 2^{29}$) — the number that Vlad remembered.
-----Output-----
Output $t$ lines, each of which is the answer to the corresponding test case. As the answer, output $a$ and $b$ ($0 < a,b \le 2^{32}$), such that $x = a \oplus b = \frac{a + b}{2}$. If there are several answers, output any of them. If there are no matching pairs, output -1.
-----Examples-----
Input
6
2
5
10
6
18
36
Output
3 1
-1
13 7
-1
25 11
50 22
-----Note-----
None
|
t = int(input())
for _ in range(t):
n = int(input())
if n % 2 != 0 or "11" in bin(n):
print(-1)
continue
print(n // 2, n // 2 + n)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR
|
Chef has an array A of length N such that A_{i} = i.
In one operation, Chef can pick any two elements of the array, delete them from A, and append either their [bitwise XOR] or their [bitwise OR] to A.
Note that after each operation, the length of the array decreases by 1.
Let F be the final number obtained after N-1 operations are made. You are given an integer X, determine if you can get F=X via some sequence of operations.
In case it is possible to get F = X, print the operations too (see the section Output format for more details), otherwise print -1.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single line containing two space-separated integers N and X.
------ Output Format ------
For each test case, output -1 if it is impossible to get X in the end.
Otherwise print N-1 lines denoting the operations.
On each line, print
- 1\ x\ y if you want replace x and y with x\ OR\ y.
- 2\ x\ y if you want replace x and y with x\ XOR\ y.
Note that x and y are the elements of the array at the time of applying the operation, and if either of them is not present in the array you will receive a WA verdict.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤ N ≤ 2^{15}$
$1 ≤ X ≤ 2^{16} - 1$
- The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$.
----- Sample Input 1 ------
3
3 2
2 2
4 7
----- Sample Output 1 ------
2 1 3
1 2 2
-1
1 1 2
1 3 3
1 3 4
----- explanation 1 ------
Test case $1$: The operations are as follows:
- Initially, the array is $A = [1, 2, 3]$
- The first move removes $1$ and $3$ and appends their $XOR$, making the array $A = [2, 2]$
- The second move removes $2$ and $2$ and appends their $OR$, making the array $A = [2]$
Test case $2$: It can be shown that no sequence of operations can achieve $F = 2$ in this case.
Test case $3$: The operations are as follows:
- Initially, the array is $A = [1, 2, 3, 4]$
- After the first move, the array is $A = [3, 4, 3]$
- After the second move, the array is $A = [4, 3]$
- After the third move, the array is $A = [7]$
|
import sys
def solve():
n, x = map(int, sys.stdin.readline().split())
maxNum = 0
for i in range(20, 0, -1):
if n & 1 << i:
maxNum = 1 << i + 1
break
if n == 2 and x != 3 or x >= maxNum or n & n - 1 == 0 and x & n == 0:
print("-1")
return
if n == 2:
print("1 1 2")
return
arr1 = set()
for i in range(1, n + 1):
arr1.add(i)
arr2 = set()
for i in range(0, 21):
num = 1 << i
if num > n:
break
if x & num == 0:
arr1.remove(num)
arr2.add(num)
num = 0
if len(arr1) > 0:
num = arr1.pop()
for i in arr1:
print("1 " + str(num) + " " + str(i))
num = num | i
comp = 0
if len(arr2) > 0:
comp = arr2.pop()
for i in arr2:
print("1 " + str(comp) + " " + str(i))
comp = comp | i
if num > 0 and comp > 0:
print("2 " + str(num) + " " + str(comp))
t = int(input()) or 1
while t:
solve()
t -= 1
|
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER
|
Chef has an array A of length N such that A_{i} = i.
In one operation, Chef can pick any two elements of the array, delete them from A, and append either their [bitwise XOR] or their [bitwise OR] to A.
Note that after each operation, the length of the array decreases by 1.
Let F be the final number obtained after N-1 operations are made. You are given an integer X, determine if you can get F=X via some sequence of operations.
In case it is possible to get F = X, print the operations too (see the section Output format for more details), otherwise print -1.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single line containing two space-separated integers N and X.
------ Output Format ------
For each test case, output -1 if it is impossible to get X in the end.
Otherwise print N-1 lines denoting the operations.
On each line, print
- 1\ x\ y if you want replace x and y with x\ OR\ y.
- 2\ x\ y if you want replace x and y with x\ XOR\ y.
Note that x and y are the elements of the array at the time of applying the operation, and if either of them is not present in the array you will receive a WA verdict.
------ Constraints ------
$1 ≤ T ≤ 5000$
$2 ≤ N ≤ 2^{15}$
$1 ≤ X ≤ 2^{16} - 1$
- The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$.
----- Sample Input 1 ------
3
3 2
2 2
4 7
----- Sample Output 1 ------
2 1 3
1 2 2
-1
1 1 2
1 3 3
1 3 4
----- explanation 1 ------
Test case $1$: The operations are as follows:
- Initially, the array is $A = [1, 2, 3]$
- The first move removes $1$ and $3$ and appends their $XOR$, making the array $A = [2, 2]$
- The second move removes $2$ and $2$ and appends their $OR$, making the array $A = [2]$
Test case $2$: It can be shown that no sequence of operations can achieve $F = 2$ in this case.
Test case $3$: The operations are as follows:
- Initially, the array is $A = [1, 2, 3, 4]$
- After the first move, the array is $A = [3, 4, 3]$
- After the second move, the array is $A = [4, 3]$
- After the third move, the array is $A = [7]$
|
for _ in range(int(input())):
n, x = map(int, input().split())
d = dict.fromkeys(list(range(1, n + 1)))
if n == 2:
if x == 3:
print("1 1 2")
else:
print(-1)
else:
for i in range(20):
ni = 1 << i
d[ni] = True
if ni & n:
msbn = i
if ni & x:
msbx = i
if msbx > msbn:
print(-1)
elif not d[n] or x & n:
val = 0
for i in range(1, n + 1):
if not d[i]:
if i > 3:
print("1 {} {}".format(i, val))
val |= i
for i in d.keys():
if i > n or not d[i]:
continue
if x & i:
print("1 {} {}".format(i, val))
val |= i
else:
print("2 {} {}".format(i, val))
val ^= i
else:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR VAR FOR VAR FUNC_CALL VAR IF VAR VAR VAR VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Read problem statements in [Bengali], [Russian], [Mandarin] and [Vietnamese] as well.
You are given an array A of N non-negative integers, where N is odd. Find the minimum non-negative integer x that satisfies the equation
(A_{1} + x) \oplus (A_{2} + x) \oplus \dots \oplus (A_{N} + x) = 0
where \oplus denotes the [bitwise XOR operation]. If no such x exists, print -1.
Note: The input of this problem is large, so use fast input/output methods.
------ Input Format ------
- First line of the input contains a single integer T, the number of test cases. The description of T test cases follows.
- The first line of each test case contains a single integer N, denoting the size of the array A.
- The second line of each test case contains N space-separated non-negative integers A_{1}, A_{2} \dots A_{N}.
------ Output Format ------
For each test case, print a single line containing one integer. If there does not exist any non-negative integer x that satisfies the given equation, print -1. Otherwise, print the minimum value of x that satisfies the given equation.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{6}$
$0 ≤ A_{i} ≤ 10^{18}$
- The value of $N$ is guaranteed to be odd.
- Sum of $N$ over all test cases is less than or equal to $10^{6}$.
------ subtasks ------
Subtask 1 (20 points):
$1≤ T≤ 10^{3}$
$1≤ N ≤ 10^{3}$
$0≤ A_{i} ≤ 10^{3}$
The value of $N$ is guaranteed to be odd.
Sum of $N$ over all test cases is less than or equal to $10^{3}$.
Subtask 2 (80 points):
Original constraints
----- Sample Input 1 ------
4
3
2 4 5
3
0 0 0
3
1 1 1
3
1 1 2
----- Sample Output 1 ------
1
0
-1
-1
----- explanation 1 ------
Test case 1:
We have to find minimum non-negative integer $x$ such that
$$(2 + x) \oplus (4 + x) \oplus (5 + x) = 0$$
Let $f(x) = (2 + x) \oplus (4 + x) \oplus (5 + x)$.
- For $x = 0$, we have
$$f(0) = (2 + 0) \oplus (4 + 0) \oplus (5 + 0) = 2\oplus 4\oplus 5 = 3$$
- For $x = 1$, we have
$$f(1) = (2 + 1) \oplus (4 + 1) \oplus (5 + 1) = 3\oplus 5\oplus 6 = 0$$
Therefore, $x = 1$ is the minimum non-negative integer that satisfies the given equation.
Test case 2:
We have to find minimum non-negative integer $x$ such that
$$(0 + x) \oplus (0 + x) \oplus (0 + x) = 0$$
i.e. $x \oplus x \oplus x = 0$. But since $0 \oplus 0 \oplus 0 = 0$, it follows that $x = 0$ is the minimum non-negative integer that satisfies the given equation.
Test case 3:
We have to find minimum non-negative integer $x$ such that
$$(1 + x) \oplus (1 + x) \oplus (1 + x) = 0$$
But $a \oplus a = 0$ and $0 \oplus a = a$ for any non-negative integer $a$. It follows that
$$(1 + x) \oplus (1 + x) \oplus (1 + x) = 0 \oplus (1 + x) = 1 + x$$
This implies that $x$ satisfies the given equation if and only if it satisfies $1 + x = 0$ if and only if $x = -1$. But $-1$ is a negative integer and therefore, there does not exist any $x$ that satisfies the given equation.
Test case 4:
We have to find minimum non-negative integer $x$ such that
$$(1 + x) \oplus (1 + x) \oplus (2 + x) = 0$$
It follows that
$$(1 + x) \oplus (1 + x) \oplus (2 + x) = 0 \oplus (2 + x) = 2 + x$$
This implies that $x$ satisfies the given equation if and only if it satisfies $2 + x = 0$, which can only happen if $x = -2$. But $-2$ is a negative integer and therefore, there does not exist any non-negative $x$ that satisfies the given equation, hence we output $-1$.
|
def compute(A, X):
S = 0
for a in A:
S ^= a + X
return S
def naive(N, A):
for x in range(10):
S = compute(A, x)
if not S:
return x
return -1
def main(N, A):
X = 0
for k in range(64):
s = compute(A, X) >> k & 1
if s == 1:
X += 1 << k
if compute(A, X):
return -1
return X
T = int(input().strip())
for _ in range(T):
N = int(input().strip())
A = [int(x) for x in input().strip().split()[:N]]
print(main(N, A))
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR RETURN VAR RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Read problem statements in [Bengali], [Russian], [Mandarin] and [Vietnamese] as well.
You are given an array A of N non-negative integers, where N is odd. Find the minimum non-negative integer x that satisfies the equation
(A_{1} + x) \oplus (A_{2} + x) \oplus \dots \oplus (A_{N} + x) = 0
where \oplus denotes the [bitwise XOR operation]. If no such x exists, print -1.
Note: The input of this problem is large, so use fast input/output methods.
------ Input Format ------
- First line of the input contains a single integer T, the number of test cases. The description of T test cases follows.
- The first line of each test case contains a single integer N, denoting the size of the array A.
- The second line of each test case contains N space-separated non-negative integers A_{1}, A_{2} \dots A_{N}.
------ Output Format ------
For each test case, print a single line containing one integer. If there does not exist any non-negative integer x that satisfies the given equation, print -1. Otherwise, print the minimum value of x that satisfies the given equation.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{6}$
$0 ≤ A_{i} ≤ 10^{18}$
- The value of $N$ is guaranteed to be odd.
- Sum of $N$ over all test cases is less than or equal to $10^{6}$.
------ subtasks ------
Subtask 1 (20 points):
$1≤ T≤ 10^{3}$
$1≤ N ≤ 10^{3}$
$0≤ A_{i} ≤ 10^{3}$
The value of $N$ is guaranteed to be odd.
Sum of $N$ over all test cases is less than or equal to $10^{3}$.
Subtask 2 (80 points):
Original constraints
----- Sample Input 1 ------
4
3
2 4 5
3
0 0 0
3
1 1 1
3
1 1 2
----- Sample Output 1 ------
1
0
-1
-1
----- explanation 1 ------
Test case 1:
We have to find minimum non-negative integer $x$ such that
$$(2 + x) \oplus (4 + x) \oplus (5 + x) = 0$$
Let $f(x) = (2 + x) \oplus (4 + x) \oplus (5 + x)$.
- For $x = 0$, we have
$$f(0) = (2 + 0) \oplus (4 + 0) \oplus (5 + 0) = 2\oplus 4\oplus 5 = 3$$
- For $x = 1$, we have
$$f(1) = (2 + 1) \oplus (4 + 1) \oplus (5 + 1) = 3\oplus 5\oplus 6 = 0$$
Therefore, $x = 1$ is the minimum non-negative integer that satisfies the given equation.
Test case 2:
We have to find minimum non-negative integer $x$ such that
$$(0 + x) \oplus (0 + x) \oplus (0 + x) = 0$$
i.e. $x \oplus x \oplus x = 0$. But since $0 \oplus 0 \oplus 0 = 0$, it follows that $x = 0$ is the minimum non-negative integer that satisfies the given equation.
Test case 3:
We have to find minimum non-negative integer $x$ such that
$$(1 + x) \oplus (1 + x) \oplus (1 + x) = 0$$
But $a \oplus a = 0$ and $0 \oplus a = a$ for any non-negative integer $a$. It follows that
$$(1 + x) \oplus (1 + x) \oplus (1 + x) = 0 \oplus (1 + x) = 1 + x$$
This implies that $x$ satisfies the given equation if and only if it satisfies $1 + x = 0$ if and only if $x = -1$. But $-1$ is a negative integer and therefore, there does not exist any $x$ that satisfies the given equation.
Test case 4:
We have to find minimum non-negative integer $x$ such that
$$(1 + x) \oplus (1 + x) \oplus (2 + x) = 0$$
It follows that
$$(1 + x) \oplus (1 + x) \oplus (2 + x) = 0 \oplus (2 + x) = 2 + x$$
This implies that $x$ satisfies the given equation if and only if it satisfies $2 + x = 0$, which can only happen if $x = -2$. But $-2$ is a negative integer and therefore, there does not exist any non-negative $x$ that satisfies the given equation, hence we output $-1$.
|
t = int(input())
def func(a):
ans = 0
xor = 0
for _ in range(64):
for c in a:
xor = xor ^ c + ans
if xor == 0:
return ans
s = "{0:b}".format(xor)
for i, c in enumerate(s[::-1]):
if int(c) == 1:
ans += 2**i
break
xor = 0
return -1
for zzzz in range(t):
n = input()
a = [int(x) for x in input().split()]
print(func(a))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL STRING VAR FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Read problem statements in [Bengali], [Russian], [Mandarin] and [Vietnamese] as well.
You are given an array A of N non-negative integers, where N is odd. Find the minimum non-negative integer x that satisfies the equation
(A_{1} + x) \oplus (A_{2} + x) \oplus \dots \oplus (A_{N} + x) = 0
where \oplus denotes the [bitwise XOR operation]. If no such x exists, print -1.
Note: The input of this problem is large, so use fast input/output methods.
------ Input Format ------
- First line of the input contains a single integer T, the number of test cases. The description of T test cases follows.
- The first line of each test case contains a single integer N, denoting the size of the array A.
- The second line of each test case contains N space-separated non-negative integers A_{1}, A_{2} \dots A_{N}.
------ Output Format ------
For each test case, print a single line containing one integer. If there does not exist any non-negative integer x that satisfies the given equation, print -1. Otherwise, print the minimum value of x that satisfies the given equation.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{6}$
$0 ≤ A_{i} ≤ 10^{18}$
- The value of $N$ is guaranteed to be odd.
- Sum of $N$ over all test cases is less than or equal to $10^{6}$.
------ subtasks ------
Subtask 1 (20 points):
$1≤ T≤ 10^{3}$
$1≤ N ≤ 10^{3}$
$0≤ A_{i} ≤ 10^{3}$
The value of $N$ is guaranteed to be odd.
Sum of $N$ over all test cases is less than or equal to $10^{3}$.
Subtask 2 (80 points):
Original constraints
----- Sample Input 1 ------
4
3
2 4 5
3
0 0 0
3
1 1 1
3
1 1 2
----- Sample Output 1 ------
1
0
-1
-1
----- explanation 1 ------
Test case 1:
We have to find minimum non-negative integer $x$ such that
$$(2 + x) \oplus (4 + x) \oplus (5 + x) = 0$$
Let $f(x) = (2 + x) \oplus (4 + x) \oplus (5 + x)$.
- For $x = 0$, we have
$$f(0) = (2 + 0) \oplus (4 + 0) \oplus (5 + 0) = 2\oplus 4\oplus 5 = 3$$
- For $x = 1$, we have
$$f(1) = (2 + 1) \oplus (4 + 1) \oplus (5 + 1) = 3\oplus 5\oplus 6 = 0$$
Therefore, $x = 1$ is the minimum non-negative integer that satisfies the given equation.
Test case 2:
We have to find minimum non-negative integer $x$ such that
$$(0 + x) \oplus (0 + x) \oplus (0 + x) = 0$$
i.e. $x \oplus x \oplus x = 0$. But since $0 \oplus 0 \oplus 0 = 0$, it follows that $x = 0$ is the minimum non-negative integer that satisfies the given equation.
Test case 3:
We have to find minimum non-negative integer $x$ such that
$$(1 + x) \oplus (1 + x) \oplus (1 + x) = 0$$
But $a \oplus a = 0$ and $0 \oplus a = a$ for any non-negative integer $a$. It follows that
$$(1 + x) \oplus (1 + x) \oplus (1 + x) = 0 \oplus (1 + x) = 1 + x$$
This implies that $x$ satisfies the given equation if and only if it satisfies $1 + x = 0$ if and only if $x = -1$. But $-1$ is a negative integer and therefore, there does not exist any $x$ that satisfies the given equation.
Test case 4:
We have to find minimum non-negative integer $x$ such that
$$(1 + x) \oplus (1 + x) \oplus (2 + x) = 0$$
It follows that
$$(1 + x) \oplus (1 + x) \oplus (2 + x) = 0 \oplus (2 + x) = 2 + x$$
This implies that $x$ satisfies the given equation if and only if it satisfies $2 + x = 0$, which can only happen if $x = -2$. But $-2$ is a negative integer and therefore, there does not exist any non-negative $x$ that satisfies the given equation, hence we output $-1$.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
nn = max(a)
if n <= 1000 and nn <= 1000:
f = 1
for i in range(n):
ans = i + a[0]
for j in range(1, n):
ans = ans ^ i + a[j]
if ans == 0:
print(i)
f = 0
break
if f:
print(-1)
else:
z = 0
u = a[0]
c = 0
for i in range(n):
if i == 0:
z += 1
if i == u:
c += 1
if z == n:
print(0)
elif c == n:
print(-1)
else:
tmp = a[0]
for ii in range(1, n):
tmp = tmp ^ a[ii]
if tmp == 0:
print(0)
else:
t = bin(tmp)
t = t[2:]
t = t[::-1]
tn = len(t)
m = max(a)
b = bin(m)
b = b[2:]
m = len(b)
mm = m
def xor(aa, x):
ans = aa[0] + x
aa[0] = aa[0] + x
for i in range(1, n):
ans = ans ^ aa[i] + x
aa[i] = aa[i] + x
return ans, aa
i = 0
ans = 0
f = 1
while i <= mm and m <= mm:
if t[i] == "1":
xx, a = xor(a, 1 << i)
ans += 1 << i
i += 1
if xx == 0:
print(ans)
f = 0
break
else:
t = bin(xx)
t = t[2:]
t = t[::-1]
m = len(t)
else:
i += 1
if f:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER
|
Read problem statements in [Bengali], [Russian], [Mandarin] and [Vietnamese] as well.
You are given an array A of N non-negative integers, where N is odd. Find the minimum non-negative integer x that satisfies the equation
(A_{1} + x) \oplus (A_{2} + x) \oplus \dots \oplus (A_{N} + x) = 0
where \oplus denotes the [bitwise XOR operation]. If no such x exists, print -1.
Note: The input of this problem is large, so use fast input/output methods.
------ Input Format ------
- First line of the input contains a single integer T, the number of test cases. The description of T test cases follows.
- The first line of each test case contains a single integer N, denoting the size of the array A.
- The second line of each test case contains N space-separated non-negative integers A_{1}, A_{2} \dots A_{N}.
------ Output Format ------
For each test case, print a single line containing one integer. If there does not exist any non-negative integer x that satisfies the given equation, print -1. Otherwise, print the minimum value of x that satisfies the given equation.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{6}$
$0 ≤ A_{i} ≤ 10^{18}$
- The value of $N$ is guaranteed to be odd.
- Sum of $N$ over all test cases is less than or equal to $10^{6}$.
------ subtasks ------
Subtask 1 (20 points):
$1≤ T≤ 10^{3}$
$1≤ N ≤ 10^{3}$
$0≤ A_{i} ≤ 10^{3}$
The value of $N$ is guaranteed to be odd.
Sum of $N$ over all test cases is less than or equal to $10^{3}$.
Subtask 2 (80 points):
Original constraints
----- Sample Input 1 ------
4
3
2 4 5
3
0 0 0
3
1 1 1
3
1 1 2
----- Sample Output 1 ------
1
0
-1
-1
----- explanation 1 ------
Test case 1:
We have to find minimum non-negative integer $x$ such that
$$(2 + x) \oplus (4 + x) \oplus (5 + x) = 0$$
Let $f(x) = (2 + x) \oplus (4 + x) \oplus (5 + x)$.
- For $x = 0$, we have
$$f(0) = (2 + 0) \oplus (4 + 0) \oplus (5 + 0) = 2\oplus 4\oplus 5 = 3$$
- For $x = 1$, we have
$$f(1) = (2 + 1) \oplus (4 + 1) \oplus (5 + 1) = 3\oplus 5\oplus 6 = 0$$
Therefore, $x = 1$ is the minimum non-negative integer that satisfies the given equation.
Test case 2:
We have to find minimum non-negative integer $x$ such that
$$(0 + x) \oplus (0 + x) \oplus (0 + x) = 0$$
i.e. $x \oplus x \oplus x = 0$. But since $0 \oplus 0 \oplus 0 = 0$, it follows that $x = 0$ is the minimum non-negative integer that satisfies the given equation.
Test case 3:
We have to find minimum non-negative integer $x$ such that
$$(1 + x) \oplus (1 + x) \oplus (1 + x) = 0$$
But $a \oplus a = 0$ and $0 \oplus a = a$ for any non-negative integer $a$. It follows that
$$(1 + x) \oplus (1 + x) \oplus (1 + x) = 0 \oplus (1 + x) = 1 + x$$
This implies that $x$ satisfies the given equation if and only if it satisfies $1 + x = 0$ if and only if $x = -1$. But $-1$ is a negative integer and therefore, there does not exist any $x$ that satisfies the given equation.
Test case 4:
We have to find minimum non-negative integer $x$ such that
$$(1 + x) \oplus (1 + x) \oplus (2 + x) = 0$$
It follows that
$$(1 + x) \oplus (1 + x) \oplus (2 + x) = 0 \oplus (2 + x) = 2 + x$$
This implies that $x$ satisfies the given equation if and only if it satisfies $2 + x = 0$, which can only happen if $x = -2$. But $-2$ is a negative integer and therefore, there does not exist any non-negative $x$ that satisfies the given equation, hence we output $-1$.
|
t = int(input())
def isbit(n, i):
b = bin(n)[2:]
if len(b) < i:
return False
if int(b[-i]):
return True
else:
return False
def xorsum(l, x):
xum = 0
for i in l:
xum ^= i + x
return xum
def do(l):
x = 0
c = xorsum(l, 0)
cb = bin(c)[2:]
k = bin(max(l))[2:]
for i in range(1, max(len(k) + 1, len(cb) + 2)):
if isbit(xorsum(l, x), i):
x += 2 ** (i - 1)
if xorsum(l, x) != 0:
print(-1)
return
print(x)
for i in range(t):
n = int(input())
l = list(map(int, input().split()))
do(l)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Bengali], [Russian], [Mandarin] and [Vietnamese] as well.
You are given an array A of N non-negative integers, where N is odd. Find the minimum non-negative integer x that satisfies the equation
(A_{1} + x) \oplus (A_{2} + x) \oplus \dots \oplus (A_{N} + x) = 0
where \oplus denotes the [bitwise XOR operation]. If no such x exists, print -1.
Note: The input of this problem is large, so use fast input/output methods.
------ Input Format ------
- First line of the input contains a single integer T, the number of test cases. The description of T test cases follows.
- The first line of each test case contains a single integer N, denoting the size of the array A.
- The second line of each test case contains N space-separated non-negative integers A_{1}, A_{2} \dots A_{N}.
------ Output Format ------
For each test case, print a single line containing one integer. If there does not exist any non-negative integer x that satisfies the given equation, print -1. Otherwise, print the minimum value of x that satisfies the given equation.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{6}$
$0 ≤ A_{i} ≤ 10^{18}$
- The value of $N$ is guaranteed to be odd.
- Sum of $N$ over all test cases is less than or equal to $10^{6}$.
------ subtasks ------
Subtask 1 (20 points):
$1≤ T≤ 10^{3}$
$1≤ N ≤ 10^{3}$
$0≤ A_{i} ≤ 10^{3}$
The value of $N$ is guaranteed to be odd.
Sum of $N$ over all test cases is less than or equal to $10^{3}$.
Subtask 2 (80 points):
Original constraints
----- Sample Input 1 ------
4
3
2 4 5
3
0 0 0
3
1 1 1
3
1 1 2
----- Sample Output 1 ------
1
0
-1
-1
----- explanation 1 ------
Test case 1:
We have to find minimum non-negative integer $x$ such that
$$(2 + x) \oplus (4 + x) \oplus (5 + x) = 0$$
Let $f(x) = (2 + x) \oplus (4 + x) \oplus (5 + x)$.
- For $x = 0$, we have
$$f(0) = (2 + 0) \oplus (4 + 0) \oplus (5 + 0) = 2\oplus 4\oplus 5 = 3$$
- For $x = 1$, we have
$$f(1) = (2 + 1) \oplus (4 + 1) \oplus (5 + 1) = 3\oplus 5\oplus 6 = 0$$
Therefore, $x = 1$ is the minimum non-negative integer that satisfies the given equation.
Test case 2:
We have to find minimum non-negative integer $x$ such that
$$(0 + x) \oplus (0 + x) \oplus (0 + x) = 0$$
i.e. $x \oplus x \oplus x = 0$. But since $0 \oplus 0 \oplus 0 = 0$, it follows that $x = 0$ is the minimum non-negative integer that satisfies the given equation.
Test case 3:
We have to find minimum non-negative integer $x$ such that
$$(1 + x) \oplus (1 + x) \oplus (1 + x) = 0$$
But $a \oplus a = 0$ and $0 \oplus a = a$ for any non-negative integer $a$. It follows that
$$(1 + x) \oplus (1 + x) \oplus (1 + x) = 0 \oplus (1 + x) = 1 + x$$
This implies that $x$ satisfies the given equation if and only if it satisfies $1 + x = 0$ if and only if $x = -1$. But $-1$ is a negative integer and therefore, there does not exist any $x$ that satisfies the given equation.
Test case 4:
We have to find minimum non-negative integer $x$ such that
$$(1 + x) \oplus (1 + x) \oplus (2 + x) = 0$$
It follows that
$$(1 + x) \oplus (1 + x) \oplus (2 + x) = 0 \oplus (2 + x) = 2 + x$$
This implies that $x$ satisfies the given equation if and only if it satisfies $2 + x = 0$, which can only happen if $x = -2$. But $-2$ is a negative integer and therefore, there does not exist any non-negative $x$ that satisfies the given equation, hence we output $-1$.
|
def binary(c):
return "{0:b}".format(int(c))
def find_one(a):
one_index = 0
dup = a
while 1:
if dup % 10 == 1:
return one_index
else:
one_index += 1
dup = dup // 10
return None
def xor(n, arr, i):
xor_val = arr[0] + i
for l in range(1, n):
xor_val = xor_val ^ arr[l] + i
return xor_val
def correct(n, arr):
maximum = max(arr)
bin_max = binary(maximum)
len_bin_max = len(bin_max)
ans = 0
jump = 0
counter = 0
while counter < len_bin_max:
counter += 1
xor_val = xor(n, arr, jump)
if xor_val == 0:
print(ans)
return 0
else:
bin = binary(xor_val)
bin = int(bin)
one = find_one(bin)
jump += 2**one
ans += 2**one
print(-1)
return 0
t = int(input())
for l in range(t):
n = int(input())
arr = [int(x) for x in input().split()]
correct(n, arr)
|
FUNC_DEF RETURN FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NONE FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
|
Read problem statements in [Bengali], [Russian], [Mandarin] and [Vietnamese] as well.
You are given an array A of N non-negative integers, where N is odd. Find the minimum non-negative integer x that satisfies the equation
(A_{1} + x) \oplus (A_{2} + x) \oplus \dots \oplus (A_{N} + x) = 0
where \oplus denotes the [bitwise XOR operation]. If no such x exists, print -1.
Note: The input of this problem is large, so use fast input/output methods.
------ Input Format ------
- First line of the input contains a single integer T, the number of test cases. The description of T test cases follows.
- The first line of each test case contains a single integer N, denoting the size of the array A.
- The second line of each test case contains N space-separated non-negative integers A_{1}, A_{2} \dots A_{N}.
------ Output Format ------
For each test case, print a single line containing one integer. If there does not exist any non-negative integer x that satisfies the given equation, print -1. Otherwise, print the minimum value of x that satisfies the given equation.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{6}$
$0 ≤ A_{i} ≤ 10^{18}$
- The value of $N$ is guaranteed to be odd.
- Sum of $N$ over all test cases is less than or equal to $10^{6}$.
------ subtasks ------
Subtask 1 (20 points):
$1≤ T≤ 10^{3}$
$1≤ N ≤ 10^{3}$
$0≤ A_{i} ≤ 10^{3}$
The value of $N$ is guaranteed to be odd.
Sum of $N$ over all test cases is less than or equal to $10^{3}$.
Subtask 2 (80 points):
Original constraints
----- Sample Input 1 ------
4
3
2 4 5
3
0 0 0
3
1 1 1
3
1 1 2
----- Sample Output 1 ------
1
0
-1
-1
----- explanation 1 ------
Test case 1:
We have to find minimum non-negative integer $x$ such that
$$(2 + x) \oplus (4 + x) \oplus (5 + x) = 0$$
Let $f(x) = (2 + x) \oplus (4 + x) \oplus (5 + x)$.
- For $x = 0$, we have
$$f(0) = (2 + 0) \oplus (4 + 0) \oplus (5 + 0) = 2\oplus 4\oplus 5 = 3$$
- For $x = 1$, we have
$$f(1) = (2 + 1) \oplus (4 + 1) \oplus (5 + 1) = 3\oplus 5\oplus 6 = 0$$
Therefore, $x = 1$ is the minimum non-negative integer that satisfies the given equation.
Test case 2:
We have to find minimum non-negative integer $x$ such that
$$(0 + x) \oplus (0 + x) \oplus (0 + x) = 0$$
i.e. $x \oplus x \oplus x = 0$. But since $0 \oplus 0 \oplus 0 = 0$, it follows that $x = 0$ is the minimum non-negative integer that satisfies the given equation.
Test case 3:
We have to find minimum non-negative integer $x$ such that
$$(1 + x) \oplus (1 + x) \oplus (1 + x) = 0$$
But $a \oplus a = 0$ and $0 \oplus a = a$ for any non-negative integer $a$. It follows that
$$(1 + x) \oplus (1 + x) \oplus (1 + x) = 0 \oplus (1 + x) = 1 + x$$
This implies that $x$ satisfies the given equation if and only if it satisfies $1 + x = 0$ if and only if $x = -1$. But $-1$ is a negative integer and therefore, there does not exist any $x$ that satisfies the given equation.
Test case 4:
We have to find minimum non-negative integer $x$ such that
$$(1 + x) \oplus (1 + x) \oplus (2 + x) = 0$$
It follows that
$$(1 + x) \oplus (1 + x) \oplus (2 + x) = 0 \oplus (2 + x) = 2 + x$$
This implies that $x$ satisfies the given equation if and only if it satisfies $2 + x = 0$, which can only happen if $x = -2$. But $-2$ is a negative integer and therefore, there does not exist any non-negative $x$ that satisfies the given equation, hence we output $-1$.
|
def Solve():
def calc(pos, ans):
tmp, x = 0, int("1" + ans, 2)
for a in A:
tmp ^= a + x
return "1" + ans if bin(tmp)[2:][::-1].ljust(mx, "0")[pos] == "0" else "0" + ans
mx = len(bin(max(A))[2:])
ans = ""
for pos in range(mx + 1):
ans = calc(pos, ans)
if int(ans, 2) >= 2**mx:
return -1
else:
return int(ans, 2)
for _ in range(int(input())):
N = int(input())
A = [int(x) for x in input().split()]
print(Solve())
|
FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FUNC_CALL VAR BIN_OP STRING VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER VAR STRING VAR STRING BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
Read problem statements in [Bengali], [Russian], [Mandarin] and [Vietnamese] as well.
You are given an array A of N non-negative integers, where N is odd. Find the minimum non-negative integer x that satisfies the equation
(A_{1} + x) \oplus (A_{2} + x) \oplus \dots \oplus (A_{N} + x) = 0
where \oplus denotes the [bitwise XOR operation]. If no such x exists, print -1.
Note: The input of this problem is large, so use fast input/output methods.
------ Input Format ------
- First line of the input contains a single integer T, the number of test cases. The description of T test cases follows.
- The first line of each test case contains a single integer N, denoting the size of the array A.
- The second line of each test case contains N space-separated non-negative integers A_{1}, A_{2} \dots A_{N}.
------ Output Format ------
For each test case, print a single line containing one integer. If there does not exist any non-negative integer x that satisfies the given equation, print -1. Otherwise, print the minimum value of x that satisfies the given equation.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{6}$
$0 ≤ A_{i} ≤ 10^{18}$
- The value of $N$ is guaranteed to be odd.
- Sum of $N$ over all test cases is less than or equal to $10^{6}$.
------ subtasks ------
Subtask 1 (20 points):
$1≤ T≤ 10^{3}$
$1≤ N ≤ 10^{3}$
$0≤ A_{i} ≤ 10^{3}$
The value of $N$ is guaranteed to be odd.
Sum of $N$ over all test cases is less than or equal to $10^{3}$.
Subtask 2 (80 points):
Original constraints
----- Sample Input 1 ------
4
3
2 4 5
3
0 0 0
3
1 1 1
3
1 1 2
----- Sample Output 1 ------
1
0
-1
-1
----- explanation 1 ------
Test case 1:
We have to find minimum non-negative integer $x$ such that
$$(2 + x) \oplus (4 + x) \oplus (5 + x) = 0$$
Let $f(x) = (2 + x) \oplus (4 + x) \oplus (5 + x)$.
- For $x = 0$, we have
$$f(0) = (2 + 0) \oplus (4 + 0) \oplus (5 + 0) = 2\oplus 4\oplus 5 = 3$$
- For $x = 1$, we have
$$f(1) = (2 + 1) \oplus (4 + 1) \oplus (5 + 1) = 3\oplus 5\oplus 6 = 0$$
Therefore, $x = 1$ is the minimum non-negative integer that satisfies the given equation.
Test case 2:
We have to find minimum non-negative integer $x$ such that
$$(0 + x) \oplus (0 + x) \oplus (0 + x) = 0$$
i.e. $x \oplus x \oplus x = 0$. But since $0 \oplus 0 \oplus 0 = 0$, it follows that $x = 0$ is the minimum non-negative integer that satisfies the given equation.
Test case 3:
We have to find minimum non-negative integer $x$ such that
$$(1 + x) \oplus (1 + x) \oplus (1 + x) = 0$$
But $a \oplus a = 0$ and $0 \oplus a = a$ for any non-negative integer $a$. It follows that
$$(1 + x) \oplus (1 + x) \oplus (1 + x) = 0 \oplus (1 + x) = 1 + x$$
This implies that $x$ satisfies the given equation if and only if it satisfies $1 + x = 0$ if and only if $x = -1$. But $-1$ is a negative integer and therefore, there does not exist any $x$ that satisfies the given equation.
Test case 4:
We have to find minimum non-negative integer $x$ such that
$$(1 + x) \oplus (1 + x) \oplus (2 + x) = 0$$
It follows that
$$(1 + x) \oplus (1 + x) \oplus (2 + x) = 0 \oplus (2 + x) = 2 + x$$
This implies that $x$ satisfies the given equation if and only if it satisfies $2 + x = 0$, which can only happen if $x = -2$. But $-2$ is a negative integer and therefore, there does not exist any non-negative $x$ that satisfies the given equation, hence we output $-1$.
|
def getAns(entries):
xorVal = 0
answer = 0
for num in entries:
xorVal ^= num
index = 0
maxVal = max(entries)
while xorVal != 0:
if maxVal < 1 << index:
break
if xorVal & 1 << index:
answer += 1 << index
index += 1
xorVal = 0
for num in entries:
xorVal ^= num + answer
if xorVal != 0:
return -1
return answer
def main():
t = int(input())
for _ in range(t):
_ = int(input())
entries = list(map(int, input().split()))
print(getAns(entries))
main()
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER IF VAR BIN_OP NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.