description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
t = int(input())
ans = [1]
n = 10
for i in range(2, n + 1):
c = ans[:]
ans.append(i)
ans += c
for _ in range(t):
n = int(input())
print(*ans[:n])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
t = int(input())
def lsb(num):
idx = 0
while num % 2 == 0:
num = num // 2
idx = idx + 1
return idx + 1
while t > 0:
n = int(input())
ans = []
for i in range(1, n + 1):
ans.append(lsb(i))
print(*ans)
t = t - 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
s = [1]
mx = 1
while len(s) <= 1000:
temp = s.copy()
mx += 1
s.append(mx)
s.extend(temp)
for _ in range(int(input())):
n = int(input())
for i in range(n):
print(s[i], end=" ")
print()
|
ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
millors = [[1]]
for i in range(1000):
p = millors[-1]
for v in range(1, max(p) + 2):
imp = {v}
for r in p[::-1]:
if r not in imp:
imp.add(r)
else:
imp.remove(r)
if not imp:
break
if imp:
millors.append(p + [v])
break
for _ in range(int(input())):
n = int(input())
print(" ".join(str(v) for v in millors[n - 1]))
|
ASSIGN VAR LIST LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
ans = [0] * 1000
def solution(n):
def recur(l, r, ele):
nonlocal n
if l > r:
return
m = (l + r) // 2
ans[m] = ele
recur(l, m - 1, ele + 1)
recur(m + 1, r, ele + 1)
recur(0, n - 1, 1)
return ans
for _ in range(int(input())):
n = int(input())
print(*solution(n)[:n])
|
ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF FUNC_DEF IF VAR VAR RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
t = int(input())
mylist = [1]
current = 2
while len(mylist) < 1000:
newlist = [current]
newlist += mylist
mylist += newlist
current += 1
for _ in range(t):
n = int(input())
for i in range(n):
print(mylist[i], end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
T = int(input())
for t in range(T):
N = int(input())
i = 0
j = -1
A = []
curr = 1
while i < N:
if j == -1:
A.append(curr)
curr += 1
j = i - 1
i += 1
else:
A.append(A[j])
i += 1
j -= 1
for a in A:
print(a, end=" ")
print("")
|
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 ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
t = int(input())
while t:
n = int(input())
if n == 1:
ans = [1]
else:
ans = [1]
for i in range(2, 100):
ans += ans
ans = ans[: len(ans) - 1]
ans = ans + [i]
if len(ans) >= n:
break
ans = ans[:n]
for f in ans:
print(f, end=" ")
print()
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR LIST VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
final = [1]
incr = 1
while len(final) <= 1000:
temp = final.copy()
incr += 1
final.append(incr)
final += temp
def prog_name():
n = int(input())
if n == 1:
print(1)
elif n == 2:
print(1, 2)
elif n == 3:
print(1, 2, 1)
else:
for x in range(n):
print(final[x], end=" ")
print()
T = int(input())
for unique in range(T):
prog_name()
|
ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
def solveG(N):
n = len(bin(N)) - 2
A = []
l = 0
for mx in range(1, n + 1):
A.append(mx)
l += 1
if l == N:
return A
for i in range(2 ** (mx - 1) - 1):
A.append(A[i])
l += 1
if l == N:
return A
for _ in range(int(input())):
print(*solveG(int(input())))
|
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
def arr(left, right, res, n, m):
if left > right:
return
mid = (left + right) // 2
res[mid] = m
arr(left, mid - 1, res, n, m + 1)
arr(mid + 1, right, res, n, m + 1)
def main():
for _ in range(int(input())):
n = int(input())
res = [0] * n
arr(0, n - 1, res, n, 1)
print(*res)
main()
|
FUNC_DEF IF VAR VAR RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
def give(a, k):
return a[0:-1] + [k]
a = [1, 2]
k = 3
for i in range(9):
a += give(a, k)
k += 1
for _ in range(int(input())):
n = int(input())
print(*a[0:n])
|
FUNC_DEF RETURN BIN_OP VAR NUMBER NUMBER LIST VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
dp = [1]
x = 2
while len(dp) < 1000:
dp = dp + [x] + dp
x += 1
def solve():
n = int(input())
print(*dp[:n])
for _ in range(int(input())):
solve()
|
ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR LIST VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
t = int(input())
for i in range(t):
n = int(input())
m = 1
l = []
p = 1
s = []
c = 0
for j in range(n):
if c:
l1 = list(reversed(s))
l += l1[0 : n - len(l)]
c = 0
if len(l) == n:
break
if len(l) + 1 == 2**p:
m += 1
p += 1
c = 1
s = l.copy()
l.append(m)
l = " ".join([str(x) for x in l])
print(l)
|
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 ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
from sys import stdin
input = stdin.readline
def answer():
ans = [0] * n
skip, value = 2, 1
for i in range(n):
if ans[i] == 0:
for j in range(i, n, skip):
ans[j] = value
value += 1
skip *= 2
return ans
for T in range(int(input())):
n = int(input())
print(*answer())
|
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
from sys import stdin, stdout
input = stdin.readline
pows = set()
for i in range(11):
pows.add(1 << i)
t = int(input())
for _ in range(t):
n = int(input())
vals = []
arr = []
curr = 0
ind = -1
for i in range(n):
if i + 1 in pows:
curr += 1
vals.append(curr)
arr.append(curr)
ind = -1
continue
ind += 1
if ind == i:
ind = 0
arr.append(arr[ind])
print(*arr)
|
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
import sys
import time
start_time = time.time()
try:
sys.stdin = open("5.txt", "r")
except:
pass
input = sys.stdin.readline
T = int(input())
a = "1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 8 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 9 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 8 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 10 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 8 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 9 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 8 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4".split(
" "
)
for _ in range(T):
n = int(input())
print(*a[:n])
end_time = time.time()
sys.stderr.write("Time: " + str(end_time - start_time))
|
IMPORT IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR BIN_OP VAR VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
l = [1, 2, 1]
for x in range(1000):
l.append(x + 3)
l = l + l[: len(l) - 1]
if len(l) > 1000:
break
t = int(input())
while t:
n = int(input())
print(" ".join([str(l[x]) for x in range(n)]))
t = t - 1
|
ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
for _ in range(int(input())):
n = int(input())
a = [1]
i = 2
while len(a) < n:
a = a + [i] + a
i += 1
print(*a[:n])
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR LIST VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
print(
*[
" ".join([str(bin(i ^ i + 1).count("1")) for i in range(int(input()))])
for _ in range(int(input()))
],
sep="\n"
)
|
EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER STRING VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
def construct(N):
arr = []
top = 1
while len(arr) < N:
arr = arr + [top] + arr
top += 1
return arr
A = [str(x) for x in construct(1000)]
T = int(input())
for t in range(T):
N = int(input())
print(" ".join(A[:N]))
|
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR LIST VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER 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 FUNC_CALL STRING VAR VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
import sys
def input():
return sys.stdin.readline().rstrip("\r\n")
def maps():
return [int(i) for i in input().split()]
a = "1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 8 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 9 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 8 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 10 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 8 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 9 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 8 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 7 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 6 1 2 1 3 1 2 1 4".split(
" "
)
arr = [1, 2, 1]
for mx in range(3, 11):
t = arr[:]
arr.append(mx)
arr.extend(t)
for _ in range(*maps()):
(n,) = maps()
print(*arr[:n])
|
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
t = int(input())
for _ in range(t):
n = int(input())
l = []
i = 1
p = 0
while len(l) < n:
l.append(i)
for j in range(p):
l.append(l[j])
i += 1
p = 2 * p + 1
for i in range(n):
print(l[i], end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesn’t exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 ≤ T ≤ 500$
$1 ≤ N ≤ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
T = int(input())
for test in range(T):
N = int(input())
if N == 1:
print(1)
continue
elif N == 2:
print(1, 2)
continue
res = [1]
N -= 1
l = 0
max_el = 2
while N > 0:
res.append(max_el)
N -= 1
r = len(res) - 1
max_el += 1
l = 0
while l < r and N > 0:
res.append(res[l])
l += 1
N -= 1
print(" ".join([str(x) for x in res]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
Consider an array of $n$ binary integers (i.e., $1$'s and $1$'s) defined as $A=[a_0,a_1,...,a_{n-1}]$.
Let $f(i,j)$ be the bitwise XOR of all elements in the inclusive range between index $\boldsymbol{i}$ and index $j$ in array $\mbox{A}$. In other words, $f(i,j)=a_i\oplus a_{i+1}\oplus\ldots\oplus a_j$. Next, we'll define another function, $\mathrm{~g~}$:
$g(x,y)=\sum_{i=x}^{y}\sum_{j=i}^{y}f(i,j)$
Given array $\mbox{A}$ and $\textit{q}$ independent queries, perform each query on $\mbox{A}$ and print the result on a new line. A query consists of three integers, $\boldsymbol{x}$, $y$, and $\boldsymbol{\mbox{k}}$, and you must find the maximum possible $g(x,y)$ you can get by changing at most $\boldsymbol{\mbox{k}}$ elements in the array from $1$ to $1$ or from $1$ to $1$.
Note: Each query is independent and considered separately from all other queries, so changes made in one query have no effect on the other queries.
Input Format
The first line contains two space-separated integers denoting the respective values of $n$ (the number of elements in array $\mbox{A}$) and $\textit{q}$ (the number of queries).
The second line contains $n$ space-separated integers where element $\boldsymbol{i}$ corresponds to array element $a_i$ $(0\leq i<n)$.
Each line $\boldsymbol{i}$ of the $\textit{q}$ subsequent lines contains $3$ space-separated integers, $x_i$, $y_i$ and $k_i$ respectively, describing query $\boldsymbol{q}_i$ $(0\leq i<q)$.
Constraints
$1\leq n,q\leq5\times10^5$
$0\leq a_i\leq1$
$0\leq x_i\leq y_i<n$
$0\leq k_i\leq n$
Subtask
$1\leq n,q\leq5000$ and $0\leq k_i\leq1$ for $\textbf{40\%}$ of the maximum score
$n=5\times10^5$, $m=5\times10^5$ and $k_i=0$ for $20\%$ of the maximum score
Output Format
Print $\textit{q}$ lines where line $\boldsymbol{i}$ contains the answer to query $\boldsymbol{q}_i$ (i.e., the maximum value of $g(x_i,y_i)$ if no more than $k_i$ bits are changed).
Sample Input
3 2
0 0 1
0 2 1
0 1 0
Sample Output
4
0
Explanation
Given $A=[0,0,1]$, we perform the following $q=2$ queries:
If we change $a_{0}=0$ to $1$, then we get $A'=[1,0,1]$ and $g(x=0,y=2)=4$.
In this query, $g(x=0,y=1)=0$.
|
def init(A, n):
retA = [0] * (n + 1)
B = [0] * (n + 1)
tmp = 0
for i in range(n):
tmp ^= A[i]
B[i + 1] = tmp
retA[i + 1] += retA[i] + tmp
return retA, B
n, q = list(map(int, input().rstrip().split()))
A = list(map(int, input().rstrip().split()))
newA, B = init(A, n)
while q > 0:
x, y, k = list(map(int, input().rstrip().split()))
num = newA[y + 1] - newA[x]
if B[x]:
num = y + 1 - x - num
size = y - x + 2
num = abs(int(size / 2)) if k else num
print(num * (size - num))
q -= 1
|
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER
|
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of status of the n lights could be.
Suppose n lights are labeled as number [1, 2, 3 ..., n], function of these 4 buttons are given below:
Flip all the lights.
Flip lights with even numbers.
Flip lights with odd numbers.
Flip lights with (3k + 1) numbers, k = 0, 1, 2, ...
Example 1:
Input: n = 1, m = 1.
Output: 2
Explanation: Status can be: [on], [off]
Example 2:
Input: n = 2, m = 1.
Output: 3
Explanation: Status can be: [on, off], [off, on], [off, off]
Example 3:
Input: n = 3, m = 1.
Output: 4
Explanation: Status can be: [off, on, off], [on, off, on], [off, off, off], [off, on, on].
Note:
n and m both fit in range [0, 1000].
|
class Solution(object):
def flipLights(self, lightNum, performTime):
if lightNum == 0:
return 0
if performTime == 0:
return 1
if lightNum == 1:
return 2
statuNumToStatu = dict()
statuNumToStatu[0] = (False,) * lightNum
statuNumToStatu[1] = (True,) * lightNum
statuNumToStatu[2] = tuple(
True if i % 2 == 0 else False for i in range(1, lightNum + 1)
)
statuNumToStatu[3] = tuple(
True if i % 2 == 1 else False for i in range(1, lightNum + 1)
)
statuNumToStatu[4] = tuple(
True if i % 3 == 1 else False for i in range(1, lightNum + 1)
)
statuNumToStatu[4] = tuple(
True if i % 3 == 1 else False for i in range(1, lightNum + 1)
)
statuNumToStatu[1, 4] = tuple(
True if i % 3 != 1 else False for i in range(1, lightNum + 1)
)
statuNumToStatu[2, 4] = tuple(
True if (i % 2 == 0) ^ (i % 3 == 1) else False
for i in range(1, lightNum + 1)
)
statuNumToStatu[3, 4] = tuple(
True if (i % 2 == 1) ^ (i % 3 == 1) else False
for i in range(1, lightNum + 1)
)
statuNumToNextStatuNums = {
(0): [1, 2, 3, 4],
(1): [0, 2, 3, (1, 4)],
(2): [0, 1, 3, (2, 4)],
(3): [0, 1, 2, (3, 4)],
(4): [0, (1, 4), (2, 4), (3, 4)],
(1, 4): [1, 4, (2, 4), (3, 4)],
(2, 4): [2, 4, (1, 4), (3, 4)],
(3, 4): [3, 4, (1, 4), (2, 4)],
}
prevStatuNums = {0}
for eachTime in range(performTime):
nextStatuNums = set()
for eachStatuNum in prevStatuNums:
for eachNextStatu in statuNumToNextStatuNums[eachStatuNum]:
nextStatuNums.add(eachNextStatu)
prevStatuNums = nextStatuNums
allStatus = set()
for eachStatuNum in prevStatuNums:
allStatus.add(statuNumToStatu[eachStatuNum])
return len(allStatus)
|
CLASS_DEF VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR
|
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of status of the n lights could be.
Suppose n lights are labeled as number [1, 2, 3 ..., n], function of these 4 buttons are given below:
Flip all the lights.
Flip lights with even numbers.
Flip lights with odd numbers.
Flip lights with (3k + 1) numbers, k = 0, 1, 2, ...
Example 1:
Input: n = 1, m = 1.
Output: 2
Explanation: Status can be: [on], [off]
Example 2:
Input: n = 2, m = 1.
Output: 3
Explanation: Status can be: [on, off], [off, on], [off, off]
Example 3:
Input: n = 3, m = 1.
Output: 4
Explanation: Status can be: [off, on, off], [on, off, on], [off, off, off], [off, on, on].
Note:
n and m both fit in range [0, 1000].
|
class Solution(object):
def flipLights(self, n, m):
if not n:
return 0
n, b = min(6, n), set()
b.add(tuple([1] * n))
for j in range(m):
c = set()
for x in b:
for t in (
tuple([((x[i] + 1) % 2) for i in range(n)]),
tuple([(x[i] if i % 2 == 0 else (x[i] + 1) % 2) for i in range(n)]),
tuple([((x[i] + 1) % 2 if i % 2 == 0 else x[i]) for i in range(n)]),
tuple([((x[i] + 1) % 2 if i % 3 == 0 else x[i]) for i in range(n)]),
):
if t not in c:
c.add(t)
b = c
if len(b) == 8:
return 8
return len(b)
|
CLASS_DEF VAR FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR
|
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of status of the n lights could be.
Suppose n lights are labeled as number [1, 2, 3 ..., n], function of these 4 buttons are given below:
Flip all the lights.
Flip lights with even numbers.
Flip lights with odd numbers.
Flip lights with (3k + 1) numbers, k = 0, 1, 2, ...
Example 1:
Input: n = 1, m = 1.
Output: 2
Explanation: Status can be: [on], [off]
Example 2:
Input: n = 2, m = 1.
Output: 3
Explanation: Status can be: [on, off], [off, on], [off, off]
Example 3:
Input: n = 3, m = 1.
Output: 4
Explanation: Status can be: [off, on, off], [on, off, on], [off, off, off], [off, on, on].
Note:
n and m both fit in range [0, 1000].
|
class Solution:
def flipLights(self, n, m):
n = min(n, 3)
if n == 0:
return 0
if n == 1:
return 2 if m > 0 else 1
if n == 2:
if m == 0:
return 1
elif m == 1:
return 3
else:
return 4
if n == 3:
if m == 0:
return 1
elif m == 1:
return 4
elif m == 2:
return 7
else:
return 8
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER
|
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of status of the n lights could be.
Suppose n lights are labeled as number [1, 2, 3 ..., n], function of these 4 buttons are given below:
Flip all the lights.
Flip lights with even numbers.
Flip lights with odd numbers.
Flip lights with (3k + 1) numbers, k = 0, 1, 2, ...
Example 1:
Input: n = 1, m = 1.
Output: 2
Explanation: Status can be: [on], [off]
Example 2:
Input: n = 2, m = 1.
Output: 3
Explanation: Status can be: [on, off], [off, on], [off, off]
Example 3:
Input: n = 3, m = 1.
Output: 4
Explanation: Status can be: [off, on, off], [on, off, on], [off, off, off], [off, on, on].
Note:
n and m both fit in range [0, 1000].
|
class Solution:
def flipLights(self, n, m):
states = set()
for op_odd in [0, 1]:
for op_even in [0, 1]:
for op_third in [0, 1]:
op_all = m - op_odd - op_even - op_third
if op_all >= 0:
one = (op_odd + op_all + op_third) % 2
two = (op_even + op_all) % 2
three = op_odd % 2
four = (op_even + op_all + op_third) % 2
states.add((one, two, three, four)[:n])
return len(states)
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR LIST NUMBER NUMBER FOR VAR LIST NUMBER NUMBER FOR VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR
|
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of status of the n lights could be.
Suppose n lights are labeled as number [1, 2, 3 ..., n], function of these 4 buttons are given below:
Flip all the lights.
Flip lights with even numbers.
Flip lights with odd numbers.
Flip lights with (3k + 1) numbers, k = 0, 1, 2, ...
Example 1:
Input: n = 1, m = 1.
Output: 2
Explanation: Status can be: [on], [off]
Example 2:
Input: n = 2, m = 1.
Output: 3
Explanation: Status can be: [on, off], [off, on], [off, off]
Example 3:
Input: n = 3, m = 1.
Output: 4
Explanation: Status can be: [off, on, off], [on, off, on], [off, off, off], [off, on, on].
Note:
n and m both fit in range [0, 1000].
|
class Solution:
def flipLights(self, n, m):
if n == 0:
return 0
if m == 0:
return 1
if n == 1:
return 2
if n == 2:
if m >= 2:
return 4
if m == 1:
return 3
if n >= 3:
if m >= 3:
return 8
if m == 2:
return 7
if m == 1:
return 4
|
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER
|
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of status of the n lights could be.
Suppose n lights are labeled as number [1, 2, 3 ..., n], function of these 4 buttons are given below:
Flip all the lights.
Flip lights with even numbers.
Flip lights with odd numbers.
Flip lights with (3k + 1) numbers, k = 0, 1, 2, ...
Example 1:
Input: n = 1, m = 1.
Output: 2
Explanation: Status can be: [on], [off]
Example 2:
Input: n = 2, m = 1.
Output: 3
Explanation: Status can be: [on, off], [off, on], [off, off]
Example 3:
Input: n = 3, m = 1.
Output: 4
Explanation: Status can be: [off, on, off], [on, off, on], [off, off, off], [off, on, on].
Note:
n and m both fit in range [0, 1000].
|
class Solution:
def flipLights(self, n, m):
if m == 0:
return 1
lights = [True] * min(n, 3)
if m > 4:
if m & 1:
m = 3
else:
m = 4
return self.final(m, lights)
def operate(self, num, array):
if num == 1:
array = [(not i) for i in array]
elif num == 2:
for i in range(len(array)):
if i & 1:
array[i] = not array[i]
elif num == 3:
for i in range(len(array)):
if not i & 1:
array[i] = not array[i]
elif num == 4:
for i in range(len(array)):
if i % 3 == 0:
array[i] = not array[i]
return array
def final(self, num, array):
ops = [
[[1], [2], [3], [4]],
[[], [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]],
[[1], [2], [3], [4], [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]],
[[], [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [1, 2, 3, 4]],
]
res = []
for op in ops[num - 1]:
tmp = array.copy()
if not op:
res.append(tmp)
else:
for i in op:
tmp = self.operate(i, tmp)
if not tmp in res:
res.append(tmp)
return len(res)
|
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST LIST LIST NUMBER LIST NUMBER LIST NUMBER LIST NUMBER LIST LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER LIST NUMBER LIST NUMBER LIST NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR
|
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.
In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned.
Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023.
Input
The first line contains an integer n (1 ≤ n ≤ 5·105) — the number of lines.
Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant xi 0 ≤ xi ≤ 1023.
Output
Output an integer k (0 ≤ k ≤ 5) — the length of your program.
Next k lines must contain commands in the same format as in the input.
Examples
Input
3
| 3
^ 2
| 1
Output
2
| 3
^ 2
Input
3
& 1
& 3
& 5
Output
1
& 1
Input
3
^ 1
^ 2
^ 3
Output
0
Note
You can read about bitwise operations in <https://en.wikipedia.org/wiki/Bitwise_operation>.
Second sample:
Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
|
a, b = 0, 1023
for i in range(int(input())):
cmd = input()
c, x = cmd.split()
x = int(x)
if c == "|":
a, b = a | x, b | x
elif c == "&":
a, b = a & x, b & x
else:
a, b = a ^ x, b ^ x
x = 0
y = 1023
z = 0
for i in range(10):
a_i = a >> i & 1
b_i = b >> i & 1
if a_i and b_i:
x |= 1 << i
if not a_i and not b_i:
y ^= 1 << i
if a_i and not b_i:
z ^= 1 << i
print(
"""3
| {}
& {}
^ {}""".format(
x, y, z
)
)
|
ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR
|
You are a member of a bomb-disposal squad. Each bomb is identified by a unique serial id X, which is a positive integer. To disarm the bomb, a positive integral key Y needs to be entered such that X + Y = X ⊕ Y (here "⊕" denotes the bit-wise XOR operator and "+" denotes the arithmetic sum operator).
However, there are multiple such keys that satisfy the above equation. All the positive integers satisfying the above equation are arranged in a list in increasing order. Your task is to find the K^th key in this list.
Input Format :
The first line of the input gives the number of test cases, T. T test cases follow. Each test case starts with one line with two integers: X and K.
Output Format:
For each test case, output one line containing "Case #x:", where x is the test case number (starting from 1). Then, for every test case, output the K^th key that satisfies the equation.
Constraints:
X, Y and K are positive integers.
0 < T ≤ 20
0 < X, Y ≤ 10^14
0 < K ≤ 10^10
SAMPLE INPUT
2
16 3
8 1
SAMPLE OUTPUT
Case #1: 3
Case #2: 1
Explanation
For the first test case, 16 + 1 = 16 ⊕ 1 = 17, 16 + 2 = 16 ⊕ 2 = 18, 16 + 3 = 16 ⊕ 3 = 19. Hence, the answer is 3.
For the second test case, 8 + 1 = 8 ⊕ 1 = 9. Hence, the answer is 1.
|
t = 0
for _ in range(int(input())):
x, y = list(map(int, input().split()))
t += 1
c = 0
k = 1
while True:
if x + k == x ^ k:
c += 1
if c == y:
break
k += 1
print("Case #%d:" % t, k, end="")
print("")
|
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
You are a member of a bomb-disposal squad. Each bomb is identified by a unique serial id X, which is a positive integer. To disarm the bomb, a positive integral key Y needs to be entered such that X + Y = X ⊕ Y (here "⊕" denotes the bit-wise XOR operator and "+" denotes the arithmetic sum operator).
However, there are multiple such keys that satisfy the above equation. All the positive integers satisfying the above equation are arranged in a list in increasing order. Your task is to find the K^th key in this list.
Input Format :
The first line of the input gives the number of test cases, T. T test cases follow. Each test case starts with one line with two integers: X and K.
Output Format:
For each test case, output one line containing "Case #x:", where x is the test case number (starting from 1). Then, for every test case, output the K^th key that satisfies the equation.
Constraints:
X, Y and K are positive integers.
0 < T ≤ 20
0 < X, Y ≤ 10^14
0 < K ≤ 10^10
SAMPLE INPUT
2
16 3
8 1
SAMPLE OUTPUT
Case #1: 3
Case #2: 1
Explanation
For the first test case, 16 + 1 = 16 ⊕ 1 = 17, 16 + 2 = 16 ⊕ 2 = 18, 16 + 3 = 16 ⊕ 3 = 19. Hence, the answer is 3.
For the second test case, 8 + 1 = 8 ⊕ 1 = 9. Hence, the answer is 1.
|
for i in range(eval(input())):
a, k = list(map(int, input().split()))
cnt = 0
start = 1
while True:
if (a & start) << 1 > 0:
start += 1
continue
else:
cnt += 1
start += 1
if cnt == k:
break
print("Case #%d: %d" % (i + 1, start - 1))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER
|
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.
Return the quotient after dividing dividend by divisor.
The integer division should truncate toward zero.
Example 1:
Input: dividend = 10, divisor = 3
Output: 3
Example 2:
Input: dividend = 7, divisor = -3
Output: -2
Note:
Both dividend and divisor will be 32-bit signed integers.
The divisor will never be 0.
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 231 − 1 when the division result overflows.
|
class Solution:
def get_half(self, dividend, divisor):
abs_dividend = abs(dividend)
abs_divisor = abs(divisor)
num = divisor
num_temp = 0
result = 1
result_temp = 0
while num <= dividend:
num_temp = num
num += num
result_temp = result
result += result
return num_temp, result_temp
def divide(self, dividend, divisor):
MAX_INT = 2147483647
if divisor == 0:
return MAX_INT
abs_dividend = abs(dividend)
abs_divisor = abs(divisor)
if abs_dividend < abs_divisor:
return 0
minus_flag = (dividend is abs_dividend) is (divisor is abs_divisor)
final_result = 0
while abs_dividend >= abs_divisor:
num, result = self.get_half(abs_dividend, abs_divisor)
abs_dividend -= num
final_result += result
if minus_flag == 1:
if final_result > MAX_INT:
return MAX_INT
return final_result
else:
if 0 - final_result < 0 - MAX_INT - 1:
return 0 - MAX_INT
return 0 - final_result
|
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER IF VAR VAR RETURN VAR RETURN VAR IF BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN BIN_OP NUMBER VAR RETURN BIN_OP NUMBER VAR
|
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.
Return the quotient after dividing dividend by divisor.
The integer division should truncate toward zero.
Example 1:
Input: dividend = 10, divisor = 3
Output: 3
Example 2:
Input: dividend = 7, divisor = -3
Output: -2
Note:
Both dividend and divisor will be 32-bit signed integers.
The divisor will never be 0.
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 231 − 1 when the division result overflows.
|
class Solution:
def divide(self, dividend, divisor):
flag = (dividend < 0) is (divisor < 0)
dividend, divisor = abs(dividend), abs(divisor)
result = 0
while dividend >= divisor:
newDivisor, rate = divisor, 1
while dividend >= newDivisor:
dividend -= newDivisor
result += rate
newDivisor <<= 1
rate <<= 1
if not flag:
result = 0 - result
return min(max(-2147483648, result), 2147483647)
|
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR BIN_OP NUMBER VAR RETURN FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER
|
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.
Return the quotient after dividing dividend by divisor.
The integer division should truncate toward zero.
Example 1:
Input: dividend = 10, divisor = 3
Output: 3
Example 2:
Input: dividend = 7, divisor = -3
Output: -2
Note:
Both dividend and divisor will be 32-bit signed integers.
The divisor will never be 0.
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 231 − 1 when the division result overflows.
|
import sys
class Solution:
import sys
def divide(self, dividend, divisor):
maxint = 2**31 - 1
minint = -(2**31)
sign = (2 * (dividend > 0) - 1) * (2 * (divisor > 0) - 1)
quotient = 0
dividend *= 2 * (dividend > 0) - 1
divisor *= 2 * (divisor > 0) - 1
remainder = dividend
for i in reversed(list(range(32))):
if remainder == 0:
break
if divisor << i <= remainder:
remainder -= divisor << i
quotient += 1 << i
quotient *= sign
print(quotient)
if quotient > maxint or quotient < minint:
quotient = maxint
return quotient
|
IMPORT CLASS_DEF IMPORT FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR RETURN VAR
|
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.
Return the quotient after dividing dividend by divisor.
The integer division should truncate toward zero.
Example 1:
Input: dividend = 10, divisor = 3
Output: 3
Example 2:
Input: dividend = 7, divisor = -3
Output: -2
Note:
Both dividend and divisor will be 32-bit signed integers.
The divisor will never be 0.
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 231 − 1 when the division result overflows.
|
class Solution:
def divide(self, dividend, divisor):
tag = 1 if (dividend < 0) is (divisor < 0) else -1
dividend, divisor = abs(dividend), abs(divisor)
if divisor == 0:
return float("inf")
count = 0
while dividend >= divisor:
mul = 1
t = divisor
while dividend > t << 1:
t <<= 1
mul <<= 1
dividend -= t
count += mul
return min(max(-2147483648, count * tag), 2147483647)
|
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER
|
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.
Return the quotient after dividing dividend by divisor.
The integer division should truncate toward zero.
Example 1:
Input: dividend = 10, divisor = 3
Output: 3
Example 2:
Input: dividend = 7, divisor = -3
Output: -2
Note:
Both dividend and divisor will be 32-bit signed integers.
The divisor will never be 0.
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 231 − 1 when the division result overflows.
|
class Solution:
def divide(self, dividend, divisor):
if abs(dividend) < abs(divisor):
return 0
sum, count, result = 0, 0, 0
a, b = abs(dividend), abs(divisor)
while a >= b:
sum = b
count = 1
while sum + sum < a:
sum += sum
count += count
a -= sum
result += count
if dividend < 0 and divisor > 0 or dividend > 0 and divisor < 0:
result = 0 - result
return min(result, 2147483647)
|
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR RETURN FUNC_CALL VAR VAR NUMBER
|
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.
Return the quotient after dividing dividend by divisor.
The integer division should truncate toward zero.
Example 1:
Input: dividend = 10, divisor = 3
Output: 3
Example 2:
Input: dividend = 7, divisor = -3
Output: -2
Note:
Both dividend and divisor will be 32-bit signed integers.
The divisor will never be 0.
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 231 − 1 when the division result overflows.
|
class Solution:
def divide(self, dividend, divisor):
MIN_INT = -(2**31)
MAX_INT = -MIN_INT - 1
if divisor == 0 or dividend == MIN_INT and divisor == -1:
return MAX_INT
sign = 1
if dividend < 0:
sign = -sign
dividend = -dividend
if divisor < 0:
sign = -sign
divisor = -divisor
ans = bits = 0
while divisor << bits + 1 <= dividend:
bits += 1
while bits >= 0:
if dividend >= divisor << bits:
dividend -= divisor << bits
ans += 1 << bits
bits -= 1
return ans if sign == 1 else -ans
|
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER RETURN VAR NUMBER VAR VAR
|
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.
Return the quotient after dividing dividend by divisor.
The integer division should truncate toward zero.
Example 1:
Input: dividend = 10, divisor = 3
Output: 3
Example 2:
Input: dividend = 7, divisor = -3
Output: -2
Note:
Both dividend and divisor will be 32-bit signed integers.
The divisor will never be 0.
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 231 − 1 when the division result overflows.
|
class Solution:
def divide(self, dividend, divisor):
if dividend < 0 and divisor > 0 or dividend > 0 and divisor < 0:
if abs(dividend) < abs(divisor):
return 0
summ = 0
count = 0
res = 0
a = abs(dividend)
b = abs(divisor)
while a >= b:
summ = b
count = 1
while summ + summ <= a:
summ += summ
count += count
a -= summ
res += count
if dividend < 0 and divisor > 0 or dividend > 0 and divisor < 0:
res = 0 - res
if res > 2**31 - 1:
res = 2**31 - 1
return res
|
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER RETURN VAR
|
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.
Return the quotient after dividing dividend by divisor.
The integer division should truncate toward zero.
Example 1:
Input: dividend = 10, divisor = 3
Output: 3
Example 2:
Input: dividend = 7, divisor = -3
Output: -2
Note:
Both dividend and divisor will be 32-bit signed integers.
The divisor will never be 0.
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 231 − 1 when the division result overflows.
|
class Solution:
def divide(self, dividend, divisor):
positive = (dividend < 0) is (divisor < 0)
dividend, divisor, div = abs(dividend), abs(divisor), abs(divisor)
res = 0
q = 1
while dividend >= divisor:
dividend -= div
res += q
q += q
div += div
if dividend < div:
div = divisor
q = 1
if not positive:
res = -res
return min(max(-2147483648, res), 2147483647)
|
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
for z in range(t):
[a, b] = [int(j) for j in input().split()]
if a == b:
print(0)
elif a == b - 1:
print(1)
elif b == 0:
print(-1)
elif b == 1 and a != 0:
print(-1)
else:
b = b - 1
n1 = bin(a)[2:].count("1")
n2 = bin(b)[2:].count("1")
if n1 < n2:
print(1 + n2 - n1)
elif n1 == n2:
print(1 + 0)
else:
print(1 + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
for i in range(t):
a, b = list(map(int, input().split()))
if a == b:
print(0)
elif b == 0 or not a == 0 and b == 2 // 2:
print(-1)
else:
if a - b + 1 == 0:
print(1)
continue
b -= 1
count = 0
bina = bin(a)[2:]
binb = bin(b)[2:]
counta = bina.count("1")
countb = binb.count("1")
if countb == counta:
print(2 // 2)
continue
if counta > countb:
print(4 // 2)
else:
print(countb - counta + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
for z in range(int(input())):
a, b = (int(x) for x in input().split())
if a == b:
print("0")
elif b == 1 and a == 0:
print("1")
elif b == 1 or b == 0:
print("-1")
else:
c1 = b - 1
q = bin(c1)[2:]
p = bin(a)[2:]
s = p.count("1")
t = q.count("1")
if s == t:
print("1")
elif s < t:
print(t - s + 1)
else:
print("2")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
test_case = int(input())
def count_zero_one(num):
arr = [0, 0]
for n in num:
if n == 0:
arr[0] += 1
elif n == 1:
arr[1] += 1
return arr
while test_case:
a, b = input().split()
a = int(a)
b = int(b)
if a == b:
print(0)
elif a == 0 and b == 1:
print(1)
elif b == 0:
print(-1)
elif b == 1 and not a == 0:
print(-1)
else:
b = b - 1
a_bin = list(map(int, bin(a)[2:]))
b_bin = list(map(int, bin(b)[2:]))
if len(a_bin) < len(b_bin):
diff = len(b_bin) - len(a_bin)
a_bin = [0] * diff + a_bin
result = count_zero_one(b_bin)[1] - count_zero_one(a_bin)[1] + 1
if result > 0:
print(result)
else:
print(2)
test_case = test_case - 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER RETURN VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
T = int(input())
for i in range(T):
a, b = map(int, input().split(" "))
to_get = b - 1
counter_get = bin(to_get).count("1")
counter_a = bin(a).count("1")
counter_b = bin(a).count("1")
if a == b:
result = 0
elif b == 0:
if a == 0:
result = 0
else:
result = -1
elif b == 1:
if a == 0:
result = 1
else:
result = -1
elif counter_get > counter_a:
min_ops = counter_get - counter_a + 1
result = min_ops
elif counter_get < counter_a:
min_ops = 1 + 1
result = min_ops
else:
result = 1
print(result)
|
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 BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def main():
for _ in range(int(input())):
a, b = [int(x) for x in input().split()]
bina = bin(a)[2:]
binb = bin(b)[2:]
binac = bina.count("1")
binbc = binb.count("1")
extra = binac - binbc
revidx = binb[::-1].index("1") if b != 0 else 0
ans = 0
if a == b:
ans = 0
elif b == 0 and a != 0:
ans = -1
elif b == 1 and a > 1:
ans = -1
elif b == 1 and a == 0:
ans = 1
elif extra < 0:
ans = revidx - extra
elif extra == 0:
if binb[-1] == "0":
ans = revidx
else:
ans = 2
elif revidx > extra:
ans = revidx - extra
else:
ans = 2
print(ans)
main()
|
FUNC_DEF 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 FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR NUMBER STRING NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
cnt = lambda x: bin(x).count("1")
def solve(a, b):
b_orig = b
ans = 0
if a == b:
ans = 0
elif a == b - 1:
ans = 1
elif b <= 1:
ans = -1
else:
ans = abs(cnt(a) - cnt(b - 1)) + 1
if cnt(a) > cnt(b - 1):
ans = min(ans, 2)
return ans
for _ in range(int(input())):
a, b = map(int, input().split())
print(solve(a, b))
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN 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 FUNC_CALL VAR VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
for i in range(t):
a, b = [int(x) for x in input().split()]
if a == b:
print(0)
elif b == 0:
print(-1)
elif b == 1:
if a == 0:
print(1)
else:
print(-1)
else:
aa = bin(a)
bb = bin(b - 1)
oa = aa.count("1")
ob = bb.count("1")
if oa > ob:
print(2)
else:
print(ob - oa + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def StringListToNumList(L):
for i in range(0, len(L), 1):
L[i] = int(L[i])
return L
def NumberOfOnesInBinary(N):
NumOfOnes = 0
if N == 0:
pass
else:
while N > 0:
if N % 2 == 1:
NumOfOnes += 1
N = N // 2
return NumOfOnes
T = int(input(""))
for k in range(0, T, 1):
Numbers = input("")
NumList = Numbers.split(" ")
NumList = StringListToNumList(NumList)
A = NumList[0]
B = NumList[1]
if A == B:
print(0)
continue
elif A == 0 and B == 1:
print(1)
continue
elif B == 0:
print(-1)
continue
elif B == 1 and A != 0:
print(-1)
continue
B = B - 1
AOnes = NumberOfOnesInBinary(A)
BOnes = NumberOfOnesInBinary(B)
if BOnes == AOnes:
print(1)
elif BOnes < AOnes:
print(2)
else:
print(BOnes - AOnes + 1)
|
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
for i in range(t):
inp = input().split()
a = int(inp[0])
b = int(inp[1])
if a == b:
print(0)
elif a == b - 1:
print(1)
elif b <= 1:
print(-1)
else:
count1 = bin(a).count("1")
count2 = bin(b - 1).count("1")
if count1 == count2:
print(1)
elif count1 < count2:
print(count2 - count1 + 1)
elif count1 > count2:
print(2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
for j in range(t):
a, b = [int(x) for x in input().split()]
cnta1 = 0
a1 = bin(a)[2:]
b1 = bin(b)[2:]
cntb1 = 0
for i in a1:
if i == "1":
cnta1 += 1
for i in b1:
if i == "1":
cntb1 += 1
fap = 0
for i in range(1, len(b1) + 1, 1):
if b1[-i] == "1":
fap = i
break
if b == 0 or b == 1:
if b == 0:
if a:
print(-1)
else:
print(0)
if b == 1:
if a < 2:
print(b - a)
else:
print(-1)
elif cnta1 == cntb1:
if b % 2:
if b >= a:
print(min(2, b - a))
else:
print(2)
elif b >= a:
print(min(b - a, fap - 1))
else:
print(fap - 1)
elif cnta1 < cntb1:
print(cntb1 - 1 - cnta1 + fap)
elif cnta1 - cntb1 + 1 == fap - 1:
print(1)
elif cnta1 - cntb1 + 1 < fap - 1:
print(1 + fap - cnta1 + cntb1 - 2)
else:
print(2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def set_bits(n):
return bin(n).count("1")
t = int(input())
for test in range(t):
a, b = map(int, input().split())
if a == b:
ans = 0
elif b == 0 or a > 0 and b == 1:
ans = -1
else:
set_bits_a = set_bits(a)
set_bits_b_less_1 = set_bits(b - 1)
if set_bits_a <= set_bits_b_less_1:
ans = set_bits_b_less_1 - set_bits_a + 1
else:
ans = 2
print(ans)
|
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING 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 IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def val(a, b):
if a == b:
return 0
elif b == 0 and a != 0:
return -1
elif b == 1:
if a == 0:
return 1
else:
return -1
numb = bin(b - 1).count("1")
numa = bin(a).count("1")
if numb - numa + 1 >= 1:
return numb - numa + 1
else:
return 2
t = int(input())
while t:
t = t - 1
a, b = input().split()
a, b = int(a), int(b)
print(val(a, b))
|
FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
for i in range(int(input())):
a, b = (int(s) for s in input().split())
s1 = bin(a)[2:]
if a == b:
print(0)
elif b == 0:
print(-1)
elif b == 1:
if a == 0:
print(1)
else:
print(-1)
else:
s3 = bin(b - 1)[2:]
c1 = s1.count("1")
c3 = s3.count("1")
if c3 < c1:
ans1 = 1
elif c3 == c1:
ans1 = 0
else:
ans1 = c3 - c1
print(ans1 + 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 FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def ones(a):
res = 0
while a:
res += a % 2
a = a // 2
return res
def counting(a, b):
if a == b:
return 0
elif b == 0:
return -1
elif b == 1:
return 1 if a == 0 else -1
ops = ones(b - 1) - ones(a) + 1
return ops if ops > 0 else 2
for i in range(int(input())):
j, k = list(map(int, input().split()))
print(counting(j, k))
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
for t in range(int(input())):
a, b = list(map(int, input().split()))
bin_a, bin_b = "{0:b}".format(a), "{0:b}".format(b)
a_one, b_one = list(bin_a).count("1"), list(bin_b).count("1")
len_a, len_b = len(bin_a), len(bin_b)
tr_zero = 0
pos = -1
while pos > -1 * len(bin_b):
if bin_b[pos] == "0":
tr_zero += 1
pos -= 1
else:
break
b_one = b_one + tr_zero
diff = b_one - a_one
if a == b:
print(0)
elif b == 1 and a != 0 and a != 1:
print(-1)
elif b == 0 and a != 0:
print(-1)
elif b_one > a_one:
print(diff)
elif b_one <= a_one:
print(2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
for test in range(t):
a, b = map(int, input().split())
if a == b:
print(0)
continue
if a == 0 and b == 1:
print(1)
continue
if b == 0 or b == 1:
print("-1")
continue
b = b - 1
aones = 0
bones = 0
x = a
y = b
while x > 0:
if x % 2 == 1:
aones += 1
x = x // 2
while y > 0:
if y % 2 == 1:
bones += 1
y = y // 2
ans = 1
if aones < bones:
ans += bones - aones
elif aones > bones:
ans += 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 IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def calc(a, b):
s1 = bin(a)[2:]
s2 = bin(b - 1)[2:]
if s1.count("1") > s2.count("1"):
return 2
elif s1.count("1") <= s2.count("1"):
return s2.count("1") - s1.count("1") + 1
for _ in range(int(input())):
a, b = map(int, input().split())
if a == b:
print(0)
elif b - a == 1:
print(1)
elif b == 0 and a >= 1:
print(-1)
elif b == 1 and a >= 1:
print(-1)
else:
print(calc(a, b))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING RETURN NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING RETURN BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
for test in range(t):
a, b = map(int, input().split())
ans = -1
if a == b:
ans = 0
elif a == 0 and b == 1:
ans = 1
elif b > 1:
counta = 0
while a > 0:
if a & 1:
counta += 1
a >>= 1
countb = 0
index = -2
flag = 0
while b > 0:
if flag == 0:
index += 1
if b & 1:
flag = 1
countb += 1
b >>= 1
index += 1
if countb <= counta and index <= counta - countb:
ans = 2
else:
ans = countb - counta + index
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 NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def no_of_ending_zeros(r):
z = 0
for i in range(len(r) - 1, -1, -1):
if r[i] == "0":
z = z + 1
if r[i] == "1":
break
return z
for _ in range(int(input())):
N1, N2 = map(int, input().split())
A = format(N1, "b")
B = format(N2, "b")
p = -1
nez = no_of_ending_zeros(B)
if A != "0" and B == "0" or B == "1" and A != "1" and A != "0":
print(p)
continue
if A == B:
p = 0
elif A.count("1") < B.count("1"):
if nez == 0:
p = B.count("1") - A.count("1")
else:
p = B.count("1") - A.count("1") + nez
elif A.count("1") == B.count("1"):
if nez == 0:
p = 2
else:
p = nez
elif A.count("1") > B.count("1"):
if nez == 0:
p = 2
elif nez >= A.count("1") - B.count("1") + 1:
p = nez - (A.count("1") - B.count("1") + 1) + 1
else:
p = 2
print(p)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING RETURN VAR 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 VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
T = int(input())
for i in range(T):
A, B = list(map(int, input().strip().split(" ")))
C = B - 1
D = "{0:08b}".format(A)
C = "{0:08b}".format(C)
a1 = D.count("1")
b1 = C.count("1")
if B == 1 and A > 1:
print(-1)
elif a1 > b1 and A != B and A != 0 and B != 0:
print(2)
elif B == 0 and A != 0:
print(-1)
elif B == 1 and A != 0 and A != 1:
print(-1)
elif A == B:
print(0)
else:
c = b1 - a1 + 1
print(c)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
T = int(input())
for t in range(T):
A, B = map(int, input().split())
if B == 0:
if A == 0:
print(0)
else:
print(-1)
elif B == 1:
if A == 0:
print(1)
elif A == 1:
print(0)
else:
print(-1)
elif A == B:
print(0)
else:
binB = bin(B - 1)
binA = bin(A)
ctbinA = str(binA).count("1")
ctbinB = str(binB).count("1")
if ctbinA == ctbinB:
print(1)
elif ctbinA > ctbinB:
print(2)
else:
print(ctbinB - ctbinA + 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 IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def bin1(x):
res = 0
while x > 0:
res += x % 2
x = x // 2
return res
for t in range(int(input())):
a, b = map(int, input().split())
if b == a:
print(0)
elif b == 0:
print(-1)
else:
cta = bin1(a)
ctb = bin1(b - 1)
if cta > ctb:
if ctb == 0:
print(-1)
else:
print(2)
else:
print(ctb - cta + 1)
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def convert(n):
if n == 0:
return 0
else:
return (n & 1) + convert(n >> 1)
t = int(input())
for i in range(0, t):
s = input().split()
a = int(s[0])
b = int(s[1])
if a == b:
print("0")
elif a > 0 and b == 1:
print("-1")
elif b == 0:
print("-1")
else:
c = b - 1
A = convert(a)
B = convert(c)
if A < B:
count = 1 + B - A
elif A == B:
count = 1
else:
count = 2
print(count)
|
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
for i in range(t):
a, b = [int(i) for i in input().split()]
if a == b:
count = 0
elif b == 0 and a != 0:
count = -1
elif b == 1 and a != 0:
count = -1
else:
p1 = bin(a).count("1")
p2 = bin(b - 1).count("1")
if p1 > p2:
count = 2
if p2 >= p1:
count = 1 + (p2 - p1)
print(count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
i = 0
while i < t:
a, b = [int(j) for j in input().split()]
if a == b:
print("0")
elif b == 0:
print("-1")
elif b == 1:
if a != 0:
print("-1")
else:
print("1")
else:
a1 = 0
b1 = 0
while a > 0:
if a % 2 == 1:
a1 = a1 + 1
a = a // 2
b = b - 1
while b > 0:
if b % 2 == 1:
b1 = b1 + 1
b = b // 2
if a1 <= b1:
print(b1 - a1 + 1)
elif a1 > b1:
print("2")
i = i + 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
for i in range(int(input())):
a, b = map(int, input().split())
c1 = bin(a).count("1")
c2 = bin(b - 1).count("1")
ans = c2 - c1 + 1
if a == b:
print(0)
elif a == 0 and b == 1:
print(1)
elif b == 0 or b == 1:
print(-1)
elif ans <= 0:
print(2)
else:
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 FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
for _ in range(int(input())):
A, B = map(int, input().split())
a = format(A, "b")
b = format(B, "b")
if A == B:
print(0)
elif B == 1 and A >= 1 or B == 0:
print(-1)
else:
t = True
s = 0
i = -1
while t:
if b[i] == "0":
s += 1
else:
t = False
i -= 1
a1 = a.count("1")
b1 = b.count("1")
if a1 > b1:
if b1 - 1 + s == a1:
print(1)
elif a1 >= b1 - 1 + s:
print(2)
else:
print(s - a1 + b1)
elif a1 == b1:
if b[-1] == "0":
print(s)
else:
print(2)
else:
print(b1 - a1 + s)
|
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 VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
n = int(input())
for i in range(0, n):
arr = [int(x) for x in input().split(" ")]
if arr[0] == arr[1]:
print(0)
continue
if arr[1] == 0 or arr[1] == 1 and arr[0] > 0:
print(-1)
continue
nb = bin(arr[1] - 1).count("1")
na = bin(arr[0]).count("1")
if nb < na:
print(2)
continue
if nb == na:
print(1)
continue
if nb > na:
print(nb - na + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def sb(num):
binary = bin(num)
setBits = [ones for ones in binary[2:] if ones == "1"]
return len(setBits)
def doIt(x, y):
if x == y:
return 0
if y == 0:
return -1
if y == 1:
if x == 0:
return 1
return -1
kachra = sb(y - 1) - sb(x) + 1
if kachra > 0:
return kachra
else:
return 2
def main():
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
print(doIt(a, b))
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR STRING RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN VAR RETURN NUMBER 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 FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
for i in range(t):
a, b = [int(i) for i in input().split()]
if a == b:
print("0")
elif b == 1 and a > 1 or b == 0 and a != 0:
print("-1")
else:
na, nb = 0, 0
res = 0
j = a
while j != 0:
j = j & j - 1
na += 1
j = b
while j != 0:
j = j & j - 1
nb += 1
if b % 2 == 1:
if nb > na:
res = nb - na
else:
res = 2
else:
x = 2
exp = 0
while b % x == 0:
x *= 2
exp += 1
if nb > na:
res = nb - na + exp
elif exp == na - (nb - 1):
res = 1
elif exp > na - (nb - 1):
res = exp - na + nb
else:
res = 2
if b < a:
print(res)
elif b - a < res:
print(b - a)
else:
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def countone(num):
count = 0
while num > 0:
num = num & num - 1
count += 1
return count
T = int(input())
for t in range(T):
A, B = map(int, input().split())
a = "{0:b}".format(A)
b = "{0:b}".format(B)
x = len(a)
y = len(b)
anum1 = countone(A)
bnum1 = countone(B)
count = 0
if B == 0 and A > 0:
print(-1)
elif B == 1 and A > 1:
print(-1)
elif A == B:
print(0)
else:
C = B - 1
cnum1 = countone(C)
if cnum1 > anum1:
count += cnum1 - anum1
elif cnum1 < anum1:
count += 1
else:
count += 0
count += 1
print(count)
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR 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 STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def dbin(x):
return int(bin(x)[2:])
def dbin1(x):
return bin(x)[2:]
def print1(x):
if x > 0:
print(x)
else:
x = 1
print(x + 1)
def zero(x):
flag = 0
count = 0
while flag == 0 and x > 0:
if x % 10 != 0:
flag = 1
else:
count = count + 1
x = x // 10
return count
T = int(input())
for i in range(T):
n1 = input()
n2 = list(map(int, n1.split()))
A1 = n2[0]
B1 = n2[1]
A = dbin(A1)
B = dbin(B1)
A1 = dbin1(A1)
B1 = dbin1(B1)
if n2[0] == n2[1]:
print(0)
elif n2[1] == 1 and n2[0] == 0:
print(1)
elif n2[1] == 1 or n2[1] == 0:
print(-1)
else:
oneB = B1.count("1")
oneA = A1.count("1")
if oneA < oneB:
print(oneB - oneA + zero(B))
elif oneA > oneB:
B1 = dbin1(n2[1] - 1)
oneB = B1.count("1")
print1(oneB - oneA + 1)
else:
B1 = dbin1(n2[1] - 1)
output = B1.count("1") - A1.count("1") + 1
print1(output)
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN 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 FUNC_CALL VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
for cnt in range(t):
a, b = input().split()
a, b = [int(a), int(b)]
if a == b:
print(0)
elif b <= 1 and a != 0:
print(-1)
else:
binary = bin(a)
setBits = [ones for ones in binary[2:] if ones == "1"]
countA = len(setBits)
binary = bin(b)
setBits = [ones for ones in binary[2:] if ones == "1"]
countB = len(setBits)
for i in range(1, len(binary) - 1):
if binary[-i] == "1":
x = i - 1
break
countB = countB - 1 + x
if countA <= countB:
ans = countB - countA
ans += 1
print(ans)
else:
ans = 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 ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def ones(n):
o = 0
while n:
if n % 2:
o += 1
n //= 2
return o
t = int(input())
while t:
t -= 1
a, b = input().split()
if a == b:
print(0)
continue
elif b == "0":
print(-1)
continue
elif b == "1":
if a == "0":
print(1)
else:
print(-1)
continue
oa = ones(int(a))
ob = ones(int(b) - 1)
if oa > ob:
print(2)
else:
print(ob - oa + 1)
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR STRING IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
T = int(input())
for f in range(T):
inp = list(map(int, input().split()))
a = inp[0]
b = inp[1]
if a == b:
ans = 0
elif b == 1 and a > 0:
ans = -1
elif b == 0:
ans = -1
else:
b = b - 1
bbin = bin(b)
abin = bin(a)
b1 = bbin.count("1")
a1 = abin.count("1")
val = b1 - a1 + 1
if val > 0:
ans = val
else:
ans = 2
print(ans)
|
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 VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
for t in range(int(input())):
A, B = map(int, input().split())
if A == B:
print(0)
elif B == 0:
print(-1)
elif B == 1:
if A == 0:
print(1)
else:
print(-1)
else:
a, b = bin(A).count("1"), bin(B - 1).count("1")
if a == b:
print(1)
elif a < b:
print(b - a + 1)
else:
print(2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def cnt(n):
count = 0
while n > 0:
if n % 2 == 1:
count += 1
n = n // 2
return count
t = int(input())
while t > 0:
a, b = map(int, input().split())
c = cnt(a)
d = cnt(b - 1)
if a == b:
print(0)
elif b == 0 or b == 1 and a != 0:
print(-1)
elif c > d:
print(2)
else:
print(d - c + 1)
t -= 1
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR 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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def dtb(n):
g = bin(n)
k = len(g)
m = g[2:k]
return int(m)
def jkl(p):
c = 0
while p != 0:
if p % 10 == 1:
c = c + 1
p = p // 10
return c
t = int(input())
for i in range(0, t):
a, b = map(int, input().split())
if b == a:
print(0)
elif b == 0:
print(-1)
elif b == 1 and a > b:
print(-1)
else:
aa = jkl(dtb(a))
bb = jkl(dtb(b - 1))
if bb < aa:
print(2)
elif bb == aa:
print(1)
else:
print(1 + (bb - aa))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR 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 IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
a = int(input())
for i in range(a):
qq = list(map(int, input().split()))
a = qq[0]
b = qq[1]
if a == b:
print(0)
elif b == 0 or b == 1 and a != 0:
print(-1)
elif b == 1 and a == 1:
print(1)
else:
b = b - 1
a = a
q1 = bin(b)[2:].count("1") - bin(a)[2:].count("1") + 1
if q1 <= 0:
print("2")
else:
print(q1)
|
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 VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
import itertools
def bruteForceMethod(A, B):
if B == 0:
return -1
if A != 0 and B == 1:
return -1
if A == B:
return 0
if A + 1 == B:
return 1
A_ = bin(A)[2:]
B_ = bin(B)[2:]
digitsToCheck, newDigitsFormed = {A}, set()
iterationsMade = 0
while True:
iterationsMade += 1
onesSeen = set()
for a in digitsToCheck:
a = bin(a)[2:]
ones = a.count("1")
if ones in onesSeen:
continue
else:
onesSeen.add(ones)
for leadingZeroes in range(0, max(0, 10 - len(a)) + 1):
newDigitLength = len(a) + leadingZeroes
for k in itertools.combinations(range(newDigitLength), ones):
newDigitFormed = ["0"] * newDigitLength
for i in k:
newDigitFormed[i] = "1"
newDigitFormed = "".join(newDigitFormed)
newDigitFormed = int(newDigitFormed, 2) + 1
newDigitsFormed.add(newDigitFormed)
if B in newDigitsFormed:
return iterationsMade
elif iterationsMade > 9:
return -1
else:
digitsToCheck, newDigitsFormed = newDigitsFormed, set()
def clearMethod(A, B):
if A == B:
return 0
if A + 1 == B:
return 1
if A != 0 and B == 0:
return -1
if (A != 0 and A != 1) and B == 1:
return -1
A = bin(A)[2:]
B = bin(B)[2:]
A1 = A.count("1")
B1 = B.count("1")
if B[-1] == "1":
if A1 < B1:
return B1 - A1
elif A1 + 1 == B1:
return 1
elif A1 >= B1:
return 2
elif B[-1] == "0":
B = bin(int(B, 2) - 1)[2:]
B1 = B.count("1")
if A1 < B1:
return B1 - A1 + 1
elif A1 == B1:
return 1
elif A1 >= B1:
return 2
T = int(input())
for _ in range(T):
A, B = [int(x) for x in input().split()]
print(clearMethod(A, B))
|
IMPORT FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF BIN_OP VAR NUMBER VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF BIN_OP VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER STRING IF VAR VAR RETURN BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
while t:
a, b = map(int, input().split(" "))
f = 0
if a == b:
print(0)
elif a == 0 and b == 1:
print(1)
elif b == 0 or b == 1:
print(-1)
else:
f = f + 1
b = b - 1
x = 0
y = 0
while a:
if a % 2:
x += 1
a = a // 2
while b:
if b % 2:
y += 1
b = b // 2
if x < y:
f = f + y - x
elif x > y:
f = f + 1
print(f)
t = t - 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def countSetBits(num):
binary = bin(num)
setBits = [ones for ones in binary[2:] if ones == "1"]
return len(setBits)
t = int(input())
for _ in range(t):
A, B = [int(x) for x in input().split()]
set_A = countSetBits(A)
set_B = countSetBits(B - 1)
if A == B:
print("0")
elif A > 1 and B < 2 or A == 1 and B == 0:
print("-1")
elif set_B < set_A:
print("2")
else:
ans = set_B - set_A + 1
print(ans)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR STRING RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
for i in range(int(input())):
a, b = [int(x) for x in input().split()]
if a == b:
print(0)
continue
if b == 0 or b == 1 and a != 0:
print(-1)
continue
one_a = bin(a)[2:].count("1")
one_b = bin(b - 1)[2:].count("1")
if one_a > one_b:
print(2)
elif one_a <= one_b:
print(one_b - one_a + 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 IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
for t in range(int(input())):
a, b = input().split()
a, b = int(a), int(b)
if a == b:
print("0")
elif b == 0:
print(-1)
elif b == 1:
if a == 0:
print(1)
else:
print(-1)
else:
a1 = bin(a)
b1 = bin(b - 1)
a1 = a1.count("1")
b1 = b1.count("1")
if a1 == b1:
print(1)
if a1 < b1:
print(b1 - a1 + 1)
if a1 > b1:
print(2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
while t:
t = t - 1
s = input().split()
a = int(s[0])
b = int(s[1])
if a == b:
print(0)
continue
if b == 0 or b == 1 and a != 0:
print(-1)
continue
x = bin(a).count("1")
k = bin(b).count("1") + list(reversed(bin(b))).index("1") - 1
if k == x:
print(1)
if k > x:
print(k - x + 1)
if k < x:
print(2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def setBits(n):
cnt = 0
while n > 0:
rsbm = n & -n
n -= rsbm
cnt += 1
return cnt
t = int(input())
for i in range(t):
a, b = list(map(int, input().split()))
if a == b:
print(0)
continue
elif b == 0:
print(-1)
continue
elif b == 1:
if a == 0:
print(1)
continue
else:
print(-1)
continue
na = setBits(a)
nb = setBits(b - 1)
if na > nb:
print(2)
else:
print(nb - na + 1)
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def count1(n):
count = 0
while n > 0:
count += n % 2
n = n // 2
return count
for t in range(int(input())):
a, b = map(int, input().split())
oa, ob = count1(a), count1(b - 1)
ans = 0
if a == b:
ans = 0
elif b == 0:
ans = -1
elif b == 1:
if a != 0:
ans = -1
else:
ans = 1
elif oa <= ob:
ans = ob - oa + 1
else:
ans = 2
print(ans)
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR 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 VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
for T in range(int(input())):
A, B = input().split()
A = bin(int(A))[2:]
B = bin(int(B))[2:]
A1 = A.count("1")
B1 = B.count("1")
if A == B:
print(0)
continue
if B == "1" or B == "0":
print([-1, 1][B == "1" and A == "0"])
continue
B1 = B1 + (len(B) - B.rindex("1") - 1)
if B1 - A1 > 0:
print(B1 - A1)
else:
print(2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR STRING VAR STRING EXPR FUNC_CALL VAR LIST NUMBER NUMBER VAR STRING VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
for t in range(int(input())):
A, B = map(int, input().split(" "))
countA, countB = str(bin(A)).count("1"), str(bin(B - 1)).count("1")
if A == B:
print("0")
elif A != 0 and (B == 0 or B == 1):
print("-1")
pass
elif countA > countB:
print("2")
pass
else:
print(countB - countA + 1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def bcnt(x):
res = 0
for i in range(0, 64):
if x >> i & 1 == 1:
res = res + 1
return res
for _ in range(0, int(input())):
a, b = map(int, input().split())
if a == b:
print(0)
elif b == 0 and a > 0 or b == 1 and a > 1:
print(-1)
elif bcnt(a) > bcnt(b - 1):
print(2)
else:
print(bcnt(b - 1) - bcnt(a) + 1)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
for _ in range(int(input())):
a, b = [int(x) for x in input().split()]
if a == b:
print(0)
elif a == 0 and b == 1:
print(1)
elif b <= 1:
print(-1)
else:
b -= 1
x, y = bin(a)[2:], bin(b)[2:]
c1, c2 = x.count("1"), y.count("1")
if c1 == c2:
print(1)
elif c1 < c2:
print(c2 - c1 + 1)
else:
print(2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
for testc in range(int(input())):
aa, bb = map(int, input().split())
b = "{0:b}".format(bb)
a = "{0:b}".format(aa)
na = a.count("1")
nb = b.count("1")
b = "0" * 60 + b
l = len(b)
odd = False
if bb % 2 != 0:
odd = True
if nb == 0 and na != 0:
print("-1")
elif bb == 1 and (aa != 0 or aa != 1):
if aa == 0:
print("1")
elif aa == 1:
print("0")
else:
print("-1")
elif na > nb:
diff = na - nb + 1
one = 0
l = l - 1
while b[l] == "0":
l = l - 1
one += 1
if one == diff:
print("1")
elif one < diff:
print("2")
else:
print(one - diff + 1)
elif nb > na:
diff = nb - na - 1
if odd:
print(diff + 1)
else:
one = 0
l = l - 1
while b[l] == "0":
l = l - 1
one += 1
print(one + 1 + diff)
elif aa == bb:
print("0")
elif odd:
print("2")
else:
one = 0
l = l - 1
while b[l] == "0":
l = l - 1
one += 1
print(one)
|
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 STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input())
def f(A, B):
str_A = bin(A)[2:]
str_B = bin(B - 1)[2:]
lhs = str_A.count("1")
rhs = str_B.count("1")
if A == B:
return 0
if B == 0:
return -1
if B == 1:
if A == 0:
return 1
else:
return -1
if lhs == rhs:
return 1
elif lhs < rhs:
return rhs - lhs + 1
else:
return 2
for _ in range(t):
A, B = map(int, input().split())
print(f(A, B))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def count_ones(a):
return bin(a)[2:].count("1")
def count_opts(a, b):
if a == b:
return 0
elif b == 0:
return -1
elif b == 1:
if a == 0:
return 1
else:
return -1
opts = count_ones(b - 1) - count_ones(a) + 1
if opts > 0:
return opts
else:
return 2
for _ in range(int(input())):
a, b = map(int, input().split())
print(count_opts(a, b))
|
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN VAR RETURN NUMBER 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 FUNC_CALL VAR VAR VAR
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = int(input().strip())
for _ in range(t):
a, b = map(int, input().strip().split())
d = b - a
b_a = bin(a)
b_b = bin(b)
b_a = b_a[2:]
b_b = b_b[2:]
one_a = b_a.count("1")
one_b = b_b.count("1")
if d == 0:
print("0")
elif d == 1:
print("1")
elif b == 0 or b == 1:
print("-1")
elif one_a > one_b:
if b % 2 == 0:
b_b = bin(b - 1)
b_b = b_b[2:]
one_b = b_b.count("1")
if one_a > one_b:
print(2)
elif d > 0:
print(min(d, one_b - one_a + 1))
else:
print(one_b - one_a + 1)
else:
print(2)
elif one_a == one_b:
if b_b[len(b_b) - 1] == "0":
if b_b[len(b_b) - 2] == "1":
print("1")
else:
b_b = bin(b - 1)
b_b = b_b[2:]
one_b = b_b.count("1")
if d > 0:
print(min(d, one_b - one_a + 1))
else:
print(one_b - one_a + 1)
else:
print(2)
elif b & 1:
if d > 0:
print(min(d, one_b - one_a))
else:
print(one_b - one_a)
else:
b_b = bin(b - 1)
b_b = b_b[2:]
one_b = b_b.count("1")
if d > 0:
print(min(d, one_b - one_a + 1))
else:
print(one_b - one_a + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
t = input()
t = int(t)
for i in range(0, t):
cnt = 0
a, b = map(int, input().split())
if a == b:
print(0)
continue
if a == 0 and b == 1:
print(1)
continue
if b <= 1:
print(-1)
continue
b = b - 1
ba = list(map(int, list(bin(b))[2:]))
aa = list(map(int, list(bin(a))[2:]))
b_cnt = ba.count(1)
a_cnt = aa.count(1)
if a_cnt < b_cnt:
print(b_cnt - a_cnt + 1)
elif b_cnt < a_cnt:
print(2)
elif b_cnt == a_cnt:
print(1)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary number of leading zeroes (possibly without any)
shuffle the binary digits of $A$ in an arbitrary way, obtaining a number $s$
replace $A$ by $s+1$
Chef is wondering about the minimum number of operations he has to perform on $A$ in order to obtain $B$. Compute this number or determine that it is impossible.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains two space-separated integers $A$ and $B$.
------ Output ------
For each test case, print a single line containing one integer — the minimum number of operations or $-1$ if it is impossible to obtain $B$ from $A$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$0 ≤ A, B ≤ 10^{18}$
------ Subtasks ------
Subtask #1 (20 points): $A, B ≤ 2^{7}$
Subtask #2 (80 points): original constraints
----- Sample Input 1 ------
2
2 4
1 5
----- Sample Output 1 ------
2
1
----- explanation 1 ------
Example case 1: One optimal solution is to not shuffle anything, so Chef just adds $1$ twice.
Example case 2: We can obtain $5$ from $1$ in one operation.
|
def num(A):
cnt = 0
while A > 0:
if A % 2 == 1:
cnt += 1
A = A // 2
return cnt
t = int(input())
for kk in range(t):
A, B = list(map(int, input().split()))
if A == B:
print(0)
elif B == 0 and A > 0:
print(-1)
elif B == 1 and A > 1:
print(-1)
elif B == 1 and A == 0:
print(1)
else:
B -= 1
if num(A) > num(B):
print(2)
else:
print(num(B) - num(A) + 1)
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.