description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N.
Formally, let S be the set
S = \{x\oplus y \mid 1 ≤ x, y ≤ N\}
where \oplus denotes the [bitwise XOR] operation.
Find |S| (where |S| denotes the size of set S. Note that a set, by definition, has no repeated elements). The answer might be large, so output it modulo 10^{9} + 7.
------ Input Format ------
- The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case consists of a single line of input, which contains one integer N.
------ Output Format ------
For each test case, output a single line containing the answer, modulo 10^{9} + 7.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{12}$
----- Sample Input 1 ------
3
1
3
7
----- Sample Output 1 ------
1
4
8
----- explanation 1 ------
Test Case 1: $N = 1$, so the only XOR we can possibly make is $1 \oplus 1 = 0$. Thus, the answer is $1$.
Test Case 2: $N = 3$, which gives us $S = \{0, 1, 2, 3\}$ as the set of possible XORs. Thus, the answer is $|S| = 4$.
|
t = int(input())
for _ in range(t):
n = int(input())
dig = 0
ones = 0
while n:
if n & 1 == 1:
ones += 1
dig += 1
n = n // 2
sol = 2**dig % 1000000007
if ones == 1:
sol -= 1
if dig == 2:
sol -= 1
print(sol)
|
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 WHILE VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N.
Formally, let S be the set
S = \{x\oplus y \mid 1 ≤ x, y ≤ N\}
where \oplus denotes the [bitwise XOR] operation.
Find |S| (where |S| denotes the size of set S. Note that a set, by definition, has no repeated elements). The answer might be large, so output it modulo 10^{9} + 7.
------ Input Format ------
- The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case consists of a single line of input, which contains one integer N.
------ Output Format ------
For each test case, output a single line containing the answer, modulo 10^{9} + 7.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{12}$
----- Sample Input 1 ------
3
1
3
7
----- Sample Output 1 ------
1
4
8
----- explanation 1 ------
Test Case 1: $N = 1$, so the only XOR we can possibly make is $1 \oplus 1 = 0$. Thus, the answer is $1$.
Test Case 2: $N = 3$, which gives us $S = \{0, 1, 2, 3\}$ as the set of possible XORs. Thus, the answer is $|S| = 4$.
|
for _ in range(int(input())):
n = int(input())
mod = int(1000000000.0 + 7)
if n == 1 or n == 2:
print(n)
else:
binn = bin(n)[2:]
ans = 2 ** len(binn) % mod
if binn.count("1") == 1:
ans -= 1
print(ans % mod)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR STRING NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N.
Formally, let S be the set
S = \{x\oplus y \mid 1 ≤ x, y ≤ N\}
where \oplus denotes the [bitwise XOR] operation.
Find |S| (where |S| denotes the size of set S. Note that a set, by definition, has no repeated elements). The answer might be large, so output it modulo 10^{9} + 7.
------ Input Format ------
- The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case consists of a single line of input, which contains one integer N.
------ Output Format ------
For each test case, output a single line containing the answer, modulo 10^{9} + 7.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{12}$
----- Sample Input 1 ------
3
1
3
7
----- Sample Output 1 ------
1
4
8
----- explanation 1 ------
Test Case 1: $N = 1$, so the only XOR we can possibly make is $1 \oplus 1 = 0$. Thus, the answer is $1$.
Test Case 2: $N = 3$, which gives us $S = \{0, 1, 2, 3\}$ as the set of possible XORs. Thus, the answer is $|S| = 4$.
|
t = int(input())
for _ in range(t):
n = int(input())
digits = 0
x = n
while x != 0:
x >>= 1
digits += 1
largest = (1 << digits) - 1
check = 1 << digits - 1
if check != n:
largest += 1
if n == 2:
print(2)
else:
divider = pow(10, 9) + 7
ans = largest % divider
print(ans)
|
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 VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N.
Formally, let S be the set
S = \{x\oplus y \mid 1 ≤ x, y ≤ N\}
where \oplus denotes the [bitwise XOR] operation.
Find |S| (where |S| denotes the size of set S. Note that a set, by definition, has no repeated elements). The answer might be large, so output it modulo 10^{9} + 7.
------ Input Format ------
- The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case consists of a single line of input, which contains one integer N.
------ Output Format ------
For each test case, output a single line containing the answer, modulo 10^{9} + 7.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{12}$
----- Sample Input 1 ------
3
1
3
7
----- Sample Output 1 ------
1
4
8
----- explanation 1 ------
Test Case 1: $N = 1$, so the only XOR we can possibly make is $1 \oplus 1 = 0$. Thus, the answer is $1$.
Test Case 2: $N = 3$, which gives us $S = \{0, 1, 2, 3\}$ as the set of possible XORs. Thus, the answer is $|S| = 4$.
|
for _ in range(int(input())):
n = int(input())
mod = int(1000000000.0 + 7)
if n == 1 or n == 2:
print(n)
else:
ans = 1
while ans < n:
ans *= 2
if n & n - 1 == 0:
ans = ans * 2 - 1
print(ans % mod)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N.
Formally, let S be the set
S = \{x\oplus y \mid 1 ≤ x, y ≤ N\}
where \oplus denotes the [bitwise XOR] operation.
Find |S| (where |S| denotes the size of set S. Note that a set, by definition, has no repeated elements). The answer might be large, so output it modulo 10^{9} + 7.
------ Input Format ------
- The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case consists of a single line of input, which contains one integer N.
------ Output Format ------
For each test case, output a single line containing the answer, modulo 10^{9} + 7.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{12}$
----- Sample Input 1 ------
3
1
3
7
----- Sample Output 1 ------
1
4
8
----- explanation 1 ------
Test Case 1: $N = 1$, so the only XOR we can possibly make is $1 \oplus 1 = 0$. Thus, the answer is $1$.
Test Case 2: $N = 3$, which gives us $S = \{0, 1, 2, 3\}$ as the set of possible XORs. Thus, the answer is $|S| = 4$.
|
M = 1000000007
t = int(input())
for _ in range(t):
n = int(input())
num = len(bin(n)) - 2
if n <= 2:
print(n)
elif bin(n).count("1") == 1:
print((2**num - 1) % M)
else:
print(2**num % M)
|
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR
|
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N.
Formally, let S be the set
S = \{x\oplus y \mid 1 ≤ x, y ≤ N\}
where \oplus denotes the [bitwise XOR] operation.
Find |S| (where |S| denotes the size of set S. Note that a set, by definition, has no repeated elements). The answer might be large, so output it modulo 10^{9} + 7.
------ Input Format ------
- The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case consists of a single line of input, which contains one integer N.
------ Output Format ------
For each test case, output a single line containing the answer, modulo 10^{9} + 7.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{12}$
----- Sample Input 1 ------
3
1
3
7
----- Sample Output 1 ------
1
4
8
----- explanation 1 ------
Test Case 1: $N = 1$, so the only XOR we can possibly make is $1 \oplus 1 = 0$. Thus, the answer is $1$.
Test Case 2: $N = 3$, which gives us $S = \{0, 1, 2, 3\}$ as the set of possible XORs. Thus, the answer is $|S| = 4$.
|
import sys
input = sys.stdin.readline
def inp():
return int(input())
def st():
return input().rstrip("\n")
def lis():
return list(map(int, input().split()))
def ma():
return map(int, input().split())
t = inp()
p = 10**9 + 7
while t:
t -= 1
n = inp()
if n <= 2:
print(n)
else:
x = bin(n)[2:]
res = pow(2, len(x), p)
if x.count("1") == 1:
res -= 1
print(res % p)
|
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR STRING NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N.
Formally, let S be the set
S = \{x\oplus y \mid 1 ≤ x, y ≤ N\}
where \oplus denotes the [bitwise XOR] operation.
Find |S| (where |S| denotes the size of set S. Note that a set, by definition, has no repeated elements). The answer might be large, so output it modulo 10^{9} + 7.
------ Input Format ------
- The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case consists of a single line of input, which contains one integer N.
------ Output Format ------
For each test case, output a single line containing the answer, modulo 10^{9} + 7.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{12}$
----- Sample Input 1 ------
3
1
3
7
----- Sample Output 1 ------
1
4
8
----- explanation 1 ------
Test Case 1: $N = 1$, so the only XOR we can possibly make is $1 \oplus 1 = 0$. Thus, the answer is $1$.
Test Case 2: $N = 3$, which gives us $S = \{0, 1, 2, 3\}$ as the set of possible XORs. Thus, the answer is $|S| = 4$.
|
mod = 10**9 + 7
for _ in range(int(input())):
n = int(input())
if n == 1:
print(1)
continue
if n == 2:
print(2)
continue
if n & n + 1 == 0:
print((n + 1) % mod)
elif n & n - 1 == 0:
print((n * 2 - 1) % mod)
else:
print(int("1" + "0" * len(bin(n)[2:]), 2) % mod)
|
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP STRING BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR
|
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N.
Formally, let S be the set
S = \{x\oplus y \mid 1 ≤ x, y ≤ N\}
where \oplus denotes the [bitwise XOR] operation.
Find |S| (where |S| denotes the size of set S. Note that a set, by definition, has no repeated elements). The answer might be large, so output it modulo 10^{9} + 7.
------ Input Format ------
- The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case consists of a single line of input, which contains one integer N.
------ Output Format ------
For each test case, output a single line containing the answer, modulo 10^{9} + 7.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{12}$
----- Sample Input 1 ------
3
1
3
7
----- Sample Output 1 ------
1
4
8
----- explanation 1 ------
Test Case 1: $N = 1$, so the only XOR we can possibly make is $1 \oplus 1 = 0$. Thus, the answer is $1$.
Test Case 2: $N = 3$, which gives us $S = \{0, 1, 2, 3\}$ as the set of possible XORs. Thus, the answer is $|S| = 4$.
|
t = int(input())
for _ in range(t):
n = int(input())
temp = n
c = 0
ans = 0
mo = int(1000000000.0) + 7
count = 0
while n > 0:
if n % 2 != 0:
count += 1
n //= 2
c += 1
for po in range(c):
ans += 2**po
ans = (ans + 1) % mo
if temp == 2:
ans = 2
elif count == 1:
ans = 2 * temp - 1
print(ans % mo)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N.
Formally, let S be the set
S = \{x\oplus y \mid 1 ≤ x, y ≤ N\}
where \oplus denotes the [bitwise XOR] operation.
Find |S| (where |S| denotes the size of set S. Note that a set, by definition, has no repeated elements). The answer might be large, so output it modulo 10^{9} + 7.
------ Input Format ------
- The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case consists of a single line of input, which contains one integer N.
------ Output Format ------
For each test case, output a single line containing the answer, modulo 10^{9} + 7.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{12}$
----- Sample Input 1 ------
3
1
3
7
----- Sample Output 1 ------
1
4
8
----- explanation 1 ------
Test Case 1: $N = 1$, so the only XOR we can possibly make is $1 \oplus 1 = 0$. Thus, the answer is $1$.
Test Case 2: $N = 3$, which gives us $S = \{0, 1, 2, 3\}$ as the set of possible XORs. Thus, the answer is $|S| = 4$.
|
def nextPowerOf2(n):
count = 0
if n and not n & n - 1:
return n
while n != 0:
n >>= 1
count += 1
return 1 << count
for _ in range(int(input())):
n = int(input())
if n == 1 or n == 2:
print(n)
elif n & n - 1 == 0:
print((2 * n - 1) % (10**9 + 7))
else:
print(nextPowerOf2(n + 1) % (10**9 + 7))
|
FUNC_DEF ASSIGN VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER
|
You are given an integer N. Find the number of distinct XORs it is possible to make using two positive integers no larger than N.
Formally, let S be the set
S = \{x\oplus y \mid 1 ≤ x, y ≤ N\}
where \oplus denotes the [bitwise XOR] operation.
Find |S| (where |S| denotes the size of set S. Note that a set, by definition, has no repeated elements). The answer might be large, so output it modulo 10^{9} + 7.
------ Input Format ------
- The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case consists of a single line of input, which contains one integer N.
------ Output Format ------
For each test case, output a single line containing the answer, modulo 10^{9} + 7.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{12}$
----- Sample Input 1 ------
3
1
3
7
----- Sample Output 1 ------
1
4
8
----- explanation 1 ------
Test Case 1: $N = 1$, so the only XOR we can possibly make is $1 \oplus 1 = 0$. Thus, the answer is $1$.
Test Case 2: $N = 3$, which gives us $S = \{0, 1, 2, 3\}$ as the set of possible XORs. Thus, the answer is $|S| = 4$.
|
MOD = 10**9 + 7
def solve():
n = int(input())
if n == 1:
return print(1)
if n == 2:
return print(2)
bit = 1
while bit <= n:
bit <<= 1
if bit == n * 2:
bit = bit - 1
print(bit % MOD)
t = int(input())
for _ in range(t):
solve()
|
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER RETURN FUNC_CALL VAR NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
for i in range(int(input())):
n, x = map(int, input().split())
a, b, p = n, n, False
while a > 0:
if a == x:
p = True
print(b)
break
b += b & -b
a &= b
if x == 0:
print(b)
elif p == False:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
def get_bigger_pow_2(n):
p = 1
i = 0
while p <= n:
p *= 2
i += 1
return p, i
def main():
t = int(input())
for _ in range(t):
n, x = list(map(int, input().split(" ")))
if n | x != n:
print(-1)
continue
xor = n ^ x
p, i = get_bigger_pow_2(xor)
m = n >> i << i
if (m & 1 << i + 1) >> i == 1:
print(-1)
continue
if p != 1:
m += p
if m & n == x:
print(m)
else:
print(-1)
main()
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF 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 STRING IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
def mapped_read(cast):
return map(cast, input().split())
def read_list(cast):
return list(mapped_read(cast))
def count(a):
ans = 0
while a > 0:
a //= 2
ans += 1
return ans
def f(x):
cnt = 0
while x % 4 == 0:
x //= 2
cnt += 1
return cnt
def solve():
n, x = mapped_read(int)
if n == x:
print(n)
return
if x == 0:
print(2 ** count(n))
return
cnt = f(x)
if (2 ** count(n) - 1 ^ 2**cnt - 1) & n != x:
print(-1)
return
print(n + 2 ** count(n & 2**cnt - 1) - (n & 2**cnt - 1))
(n,) = mapped_read(int)
for _ in range(n):
solve()
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, x = map(int, input().split())
nn, xx = n, x
flag = 0
if n < x:
print(-1)
elif n == x:
print(n)
else:
cnt = 0
a, b = str(bin(n))[2:], str(bin(x))[2:]
b = "0" * (len(a) - len(b)) + b
cnt = len(a)
flag = 0
ans = ""
for i in range(len(a)):
if a[i] == b[i] and flag == 0:
ans += a[i]
else:
flag = 1
ans += "1"
ans = int(ans, 2) + 1
if xx <= ans & ans - 1:
print(ans)
else:
print(-1)
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
t = int(input())
for _ in range(t):
n, goal = map(int, input().split())
bin_n = bin(n)
length_n = len(bin_n) - 2
bin_goal = bin(goal)
length_goal = len(bin_goal) - 2
if n == goal:
print(n)
elif goal == 0:
print(2**length_n)
elif n < goal or length_goal != length_n:
print(-1)
else:
bin_goal = bin(goal)
length_goal = len(bin_goal) - 2
m = 0
possible = True
is_1 = [0, False]
if bin_goal[-1] == "1":
print(-1)
continue
for i in range(2, length_goal + 1):
if bin_goal[-i] == "1":
index = i
break
if bin_goal[: -index + 1] != bin_n[: -index + 1]:
print(-1)
continue
m += goal
for i in range(1, index):
if bin_n[-i] == "1":
is_1[1] = True
elif is_1[1]:
is_1 = [i - 1, False]
if not possible or is_1[1]:
print(-1)
elif is_1[0]:
print(m + 2 ** is_1[0])
else:
print(m)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
t = int(input())
def solve():
s = input()
n = int(s.split(" ")[0])
x = int(s.split(" ")[1])
if n == x:
print(n)
return
for i in range(70, -1, -1):
if n >> i & 1 != x >> i & 1:
if n >> i & 1 == 0:
print(-1)
return
else:
if n >> i + 1 & 1 == 0 and x & (1 << i + 1) - 1 == 0:
ans = (n >> i + 2 << i + 2) + (1 << i + 1)
if ans > 5000000000000000000:
print(ans)
return
print(ans)
return
print(-1)
return
while t:
t -= 1
solve()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER RETURN WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
t = int(input())
for i in range(t):
n, x = map(int, input().split(" "))
if n < x:
print(-1)
continue
m = n
current_bit = 0
current_num = n
while current_num != x and m < 1e19:
m += 1 << current_bit
if (m >> current_bit) % 2 == 0:
current_bit += 1
current_num &= m
if m >= 1e19:
print(-1)
else:
print(m)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
def read_test():
nums = input().split(" ")
return int(nums[0]), int(nums[1])
def read_input():
test_num = int(input())
tests = []
for _ in range(test_num):
tests.append(read_test())
return tests
def solve(test):
n = test[0]
x = test[1]
if n == x:
return n
n_binary = format(n, "b")
x_binary = format(x, "b")
if len(x_binary) < len(n_binary):
x_binary = "0" * (len(n_binary) - len(x_binary)) + x_binary
if len(n_binary) < len(x_binary):
n_binary = "0" * (len(x_binary) - len(n_binary)) + n_binary
diff_idx = 0
while n_binary[diff_idx] == x_binary[diff_idx]:
diff_idx += 1
if x_binary[diff_idx] == "1":
return -1
if "1" in x_binary[diff_idx:]:
return -1
if diff_idx == 0:
return int("1" + "0" * len(n_binary), 2)
if n_binary[diff_idx - 1] != "0":
return -1
return int(n_binary[: diff_idx - 1] + "1" + "0" * (len(n_binary) - diff_idx), 2)
def main():
tests = read_input()
for test in tests:
print(solve(test))
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING RETURN FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR STRING RETURN NUMBER IF STRING VAR VAR RETURN NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP STRING BIN_OP STRING FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING RETURN NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING BIN_OP STRING BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
for _ in range(int(input())):
n, x = map(int, input().split())
if len(bin(x)) > len(bin(n)):
print(-1)
continue
bin_n = bin(n)
bin_x = bin(x)
if len(bin_x) < len(bin_n):
if x:
print(-1)
continue
bin_x = "0b" + "0" * (len(bin_n) - len(bin_x)) + bin_x[2:]
i = len(bin_x) - 1
while i >= 2 and bin_x[i] == "0":
i -= 1
p = len(bin_x) - i - 1
i = 2
while i < len(bin_n):
if bin_n[i] == "1" and bin_x[i] == "0":
if p >= len(bin_n) - i:
if i == 2 or bin_x[i - 1] != "1":
s = bin_n[i:]
print(n + 2 ** len(s) - int(s, 2))
else:
print(-1)
else:
print(-1)
break
elif bin_n[i] == "0" and bin_x[i] == "1":
print(-1)
break
i += 1
else:
print(n)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING IF VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
for j in range(int(input())):
b, c = [int(j) for j in input().split()]
bc = bin(b)[2:]
cc = bin(c)[2:]
y = b
z = b
found = False
while y > 0:
if y == c:
found = True
print(z)
break
z += z & -z
y &= z
if c == 0:
print(z)
elif not found:
print(-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 ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
for _ in range(int(input())):
a, b = input().split()
a = int(a)
b = int(b)
if b > a:
print(-1)
continue
if b == a:
print(a)
continue
n = str(bin(a))[2:]
c = str(bin(b))[2:]
if b == 0:
print(2 ** len(n))
continue
if len(c) != len(n):
print(-1)
continue
possible = True
spot = 0
thing2 = False
ans = 0
for r in range(len(n)):
if thing2 and c[r] == "1":
possible = False
break
if n[r] != c[r]:
if c[r] != "0" or c[r - 1] != "0":
possible = False
break
elif not thing2:
thing2 = True
spot = len(n) - r
ans += 2**spot
if not thing2:
ans += 2 ** (len(n) - r - 1) * int(n[r])
if not possible:
print(-1)
else:
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
for _ in range(int(input())):
m, x = map(int, input().split())
dicM = {}
dicX = {}
ok = True
pos = -1
A = -1
ans = 0
for i in range(63):
if 1 << i & x != 0:
dicX[i] = 1
else:
dicX[i] = 0
if 1 << i & m != 0:
dicM[i] = 1
else:
dicM[i] = 0
if dicM[i] != dicX[i]:
if dicM[i] == 1:
pos = i + 1
else:
ok = False
elif dicX[i] == 1 and dicX[i] == dicM[i]:
ans += 1 << i
A = i
if A != -1 and pos != -1 and pos >= A:
ok = False
if pos != -1:
ans += 1 << pos
print(ans) if ok else print("-1")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
t = int(input())
for _ in range(t):
n, x = [int(i) for i in input().split()]
if n == x:
print(n)
continue
if x > n:
print(-1)
else:
x_b = bin(x)[2:]
n_b = bin(n)[2:]
le = max(len(x_b), len(n_b))
x_b = "0" * (le - len(x_b)) + x_b
n_b = "0" * (le - len(n_b)) + n_b
chislo = ""
add = ""
f = 0
for i in range(le):
if f and x_b[i] == "1":
print(-1)
break
elif f:
chislo = chislo + "0"
elif x_b[i] == n_b[i] == "1":
chislo = chislo + "1"
elif x_b[i] == "0" and n_b[i] == "1":
if chislo and chislo[-1] == "1":
print(-1)
break
chislo = chislo[:-1] + "10"
f = 1
elif x_b[i] == "1" and n_b[i] == "0":
print(-1)
break
else:
chislo = chislo + "0"
else:
print(int(chislo, 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 IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR STRING IF VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR STRING IF VAR VAR STRING VAR VAR STRING IF VAR VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
def bin_to_dec(x):
y = 0
for i in x:
y *= 2
y += int(i)
return y
t = int(input())
for _ in range(t):
n, x = map(int, input().split())
a = bin(n)
b = bin(x)
if n == x:
print(n)
continue
if x == 0:
print(1 << len(a) - 2)
continue
if n < x:
print(-1)
continue
a = a[2:]
b = b[2:]
if len(a) != len(b):
print(-1)
continue
i = 0
while i < len(a):
if a[i] != b[i]:
break
i += 1
k = i
ans = 1
while k < len(b):
if b[k] != "0":
ans = 0
k += 1
if not ans:
print(-1)
continue
if a[i - 1] == "1":
print(-1)
continue
else:
l = []
j = 0
while j < i - 1:
l.append(a[j])
j += 1
l.append("1")
for w in range(len(a) - i):
l.append("0")
s = ""
for char in l:
s = s + char
print(bin_to_dec(s))
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR 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 VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
t = int(input())
for tc in range(t):
n, x = map(int, input().split())
if n == x:
print(x)
continue
sn = bin(n)[2:]
ln = len(sn)
sx = bin(x)[2:]
lx = len(sx)
if x == 0:
print(1 << ln)
continue
if ln != lx:
print(-1)
continue
i = 0
while sn[i] == sx[i]:
i += 1
if "1" in sx[i + 1 :]:
print(-1)
continue
if sn[i] == "1":
if i > 0 and sn[i - 1] == "1":
print(-1)
else:
tmp = sn[: i - 1] + "1" + "0" * (ln - i)
print(int(tmp, base=2))
else:
print(-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 VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR STRING IF VAR NUMBER VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING BIN_OP STRING BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
def ii(num=False):
i = input().split()
if num:
return int(i[0])
try:
return list(map(int, i))
except Exception:
return i
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
for _ in range(ii(1)):
max_bit = 63
n, x = ii()
if n == x:
print(n)
continue
if n < x:
print(-1)
continue
arr_n = [0] * max_bit
arr_x = [0] * max_bit
for i in range(max_bit):
arr_n[max_bit - i - 1] = n >> i & 1
arr_x[max_bit - i - 1] = x >> i & 1
left = 0
flag = True
while left < max_bit:
if arr_n[left] == arr_x[left]:
left += 1
elif arr_n[left] > arr_x[left]:
break
else:
flag = False
break
if flag:
bit = max_bit - left
m = (n >> bit) + 1 << bit
if m & n != x:
flag = False
else:
print(m)
if not flag:
print(-1)
|
FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR RETURN FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
def solve():
n, x = map(int, input().split())
if x > n:
print(-1)
return
n = bin(n)[2:]
x = bin(x)[2:]
ln = len(n)
lx = len(x)
ans = []
if x == "0":
if n == "0":
print(0)
return
myans = "1" + "0" * ln
print(int(myans, 2))
return
if lx < ln:
print(-1)
return
for i in range(lx):
ans.append(x[i])
if n[i] == "0" and x[i] == "1":
print(-1)
return
la = len(ans)
for i in range(la):
if n[i] < ans[i]:
myans = "".join(ans)
print(int(myans, 2))
return
elif n[i] > ans[i]:
for j in range(i - 1, -1, -1):
if ans[j] == "0":
ans[j] = "1"
for k in range(j + 1, la):
if x[k] != "0":
print(-1)
return
myans = "".join(ans)
print(int(myans, 2))
return
print(-1)
return
myans = "".join(ans)
print(int(myans, 2))
return
for _ in range(int(input())):
solve()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR STRING IF VAR STRING EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP STRING BIN_OP STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
for _ in range(int(input())):
n, x = map(int, input().split())
f = 0
for i in range(64):
if n >> i & 1 and x >> i & 1:
f = 1
if f == 1 and n >> i & 1 and x >> i & 1 == 0:
f = 2
break
if n >> i & 1 == 0 and x >> i & 1:
f = 2
break
if f == 2:
print(-1)
continue
ans = 0
for i in range(64, -1, -1):
if n >> i & 1 and x >> i & 1 == 0:
ans = 1 << i + 1
r = 0
for j in range(i + 1):
if n >> j & 1:
r += 1 << j
ans -= r
break
n += ans
f = 0
for i in range(64):
if n >> i & 1 == 0 and x >> i & 1:
f = 1
break
if f:
print(-1)
else:
print(n)
|
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 NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
def find_m(n, x):
f = [0] * 60
for i in range(60):
if ~n >> i & 1:
f[i] = n
else:
f[i] = (n & ~((1 << i) - 1)) + (1 << i)
m = n
for i in range(60):
if ~x >> i & 1:
m = max(m, f[i])
for i in range(60):
if x >> i & 1:
if m >= f[i]:
return -1
return m
def main():
t = int(input())
for i in range(t):
n, x = map(int, input().split())
result = find_m(n, x)
print(result)
main()
|
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN NUMBER RETURN VAR 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 ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
t = int(input())
for _ in range(t):
n, x = map(int, input().split())
N = [0] * 62
X = [0] * 62
f = True
for i in range(62):
if n & 1 << i:
N[i] += 1
if x & 1 << i:
X[i] += 1
if X[i] and not N[i]:
f = False
break
if not f:
print(-1)
continue
i = 0
a = 0
p = 0
while i < 62:
if N[i] and not X[i]:
a += 2**i
N[i] = 0
if p != 0:
a -= 2**p
p = 0
j = i + 1
while j < 62:
if N[j] and not X[j]:
N[j] = 0
j += 1
elif N[j] and X[j]:
f = False
break
else:
break
i = j
p = j
elif N[i] == X[i] == 1:
break
else:
i += 1
if not f:
print(-1)
continue
for i in range(62):
if N[i] != X[i]:
f = False
break
if not f:
print(-1)
continue
print(a + n)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
T = int(input())
def b(a, b):
return a >> b & 1
for t in range(T):
n, x = map(int, input().split())
low, high = n, 10**20
ac = 0
for i in range(max(x.bit_length(), n.bit_length())):
if not b(n, i) and not b(x, i):
pass
elif not b(n, i) and b(x, i):
low = -1
break
elif b(n, i) and not b(x, i):
low = n + ac + 1
else:
high = n + ac
if not b(n, i):
ac += 2**i
if low > high:
low = -1
break
print(low)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
for _ in range(int(input())):
[n, x] = list(map(int, input().split()))
orin, orix = n, x
if n == x:
print(n)
continue
if n < x:
print(-1)
continue
maxi = 0
power = 0
yes = 1
while n or x:
if x % 2 == 1 and n % 2 == 0:
print(-1)
yes = 0
break
if x % 2 == 1 and n % 2 == 1:
if n != x:
print(-1)
yes = 0
break
elif power == maxi + 1:
print(-1)
yes = 0
break
else:
print(orix + 2 ** (maxi + 1))
yes = 0
break
if x % 2 == 0 and n % 2 == 1:
maxi = power
n, x = n // 2, x // 2
power += 1
if yes == 1:
print(2 ** (maxi + 1))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
t = int(input())
for i in range(t):
n, x = map(int, input().split())
st, st1 = bin(n)[2:], bin(x)[2:]
if n & x != x:
print(-1)
elif n == x:
print(x)
else:
while len(st) != 64:
st = "0" + st
while len(st1) != 64:
st1 = "0" + st1
vsp = [0] * 64
vsp[63] = int(st1[63])
for i in range(62, -1, -1):
vsp[i] = vsp[i + 1] + int(st1[i])
ind = -1
i = 0
while st[i] == st1[i]:
if vsp[i] == 0:
ind = i
i += 1
if ind == -1:
print(-1)
else:
res = st1[:ind] + "1" + "0" * (64 - ind - 1)
print(int(res, 2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING BIN_OP STRING BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
for j in range(int(input())):
n, x = map(int, input().split())
if n == x:
print(n)
continue
if x > n:
print("-1")
continue
a = list(bin(n)[2:])
b = list(bin(x)[2:])
t = len(b)
s = len(a) - t
b1 = ["0"] * s
b = b1 + b
f = 0
r = len(a)
j = r - 1
t = 0
while True:
if j == -1:
break
if b[j] == "1" and a[j] == "0":
t = 1
print("-1")
break
if b[j] == "1" and a[j] == "1":
f = 1
if a[j] == "1" and b[j] == "0" and f == 1:
print("-1")
t = 1
break
j -= 1
if t == 1:
continue
flg = 0
req = 0
for j in range(r):
if a[j] == "1" and b[j] == "0":
req = j
break
if req != 0:
reqs = "".join(a[0 : req - 1])
else:
reqs = ""
reqs = reqs + "1"
rem = "".join(["0"] * (r - req))
reqs = reqs + rem
if int(reqs, 2) < n:
print(-1)
continue
print(int(reqs, 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 VAR IF VAR VAR EXPR FUNC_CALL VAR STRING 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 VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL STRING BIN_OP LIST STRING BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
def solve(n, x):
if n < x:
print(-1)
return
if n == x:
print(n)
return
bn = bin(n)[2:][::-1]
bx = bin(x)[2:][::-1]
bm = bn[:]
if x == 0:
print(2 ** len(bn))
return
if len(bx) != len(bn):
print(-1)
return
last1 = -1
no_more = False
for i in range(len(bn)):
if bn[i] == "0" and bx[i] == "1":
print(-1)
return
if bn[i] == "1":
if bx[i] == "1":
no_more = True
else:
if no_more:
print(-1)
return
last1 = i
bm = bm[:i] + "0" + bm[i + 1 :]
if bx[last1 + 1] == "1":
print(-1)
return
bm = bm[: last1 + 1] + "1" + bm[last1 + 2 :]
print(int(bm[::-1], 2))
t = int(input())
for i in range(t):
s = input()
n, x = int(s.split()[0]), int(s.split()[1])
solve(n, x)
|
FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR RETURN IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR STRING IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
def func():
a, b = map(int, input().split())
if b > a:
print(-1)
return
if b == a:
print(a)
return
c = a - b
d = a
ld = []
lc = []
cnt = 0
while d != 0:
if d % 2 != 0:
ld.append(cnt)
d = d // 2
cnt = cnt + 1
cnt = 0
while c != 0:
if c % 2 != 0:
lc.append(cnt)
c = c // 2
cnt = cnt + 1
if cnt in ld:
print(-1)
return
ans = a + pow(2, cnt)
for i in range(len(lc)):
if lc[i] not in ld or lc[i] != ld[i]:
print(-1)
return
ans = ans - pow(2, lc[i])
print(ans)
for i in range(int(input())):
func()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
def ii(num=False):
i = input().split()
if num:
return int(i[0])
try:
return list(map(int, i))
except Exception:
return i
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
for _ in range(ii(1)):
max_bit = 63
n, x = ii()
xor = n ^ x
left = 0
if xor == 0:
print(n)
continue
while left < 63 and xor >> max_bit - left & 1 == 0:
left += 1
bit = max_bit - left
m = (n >> bit) + 1 << bit
if m & n != x:
print(-1)
else:
print(m)
|
FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR RETURN FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
t = int(input())
for i in range(t):
arr = list(map(int, input().split()))
n = arr[0]
x = arr[1]
t1 = n
temp = n
fnd = 0
while t1 > 0:
if t1 == x:
fnd = 1
break
temp = temp + (temp & -temp)
t1 = t1 & temp
if fnd != 0 or x == 0:
print(temp)
elif fnd == 0:
print("-1")
|
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 ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
import sys
input = sys.stdin.readline
MAX = int(1e18)
def solve():
N, X = list(map(int, input().split()))
if N == X:
print(N)
elif X == 0:
A = 1
while A <= N:
A <<= 1
print(A)
else:
A = list(bin(N)[2:])
N1 = len(A)
D = {}
for i in range(N1 - 1, 0, -1):
if A[i - 1] + A[i] == "01":
A[i] = "0"
A[i - 1] = "1"
t = eval("0b" + "".join(A))
A[i - 1] = "0"
x = eval("0b" + "".join(A))
D[x] = min(D.get(x, MAX), t)
elif A[i] == "1":
A[i] = "0"
if X in D:
print(D[X])
else:
print(-1)
for _ in range(int(input())):
solve()
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP STRING FUNC_CALL STRING VAR ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP STRING FUNC_CALL STRING VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
t = int(input(""))
for _ in range(t):
n, x = [int(x) for x in input("").split(" ")]
if x > n:
print(-1)
continue
if x & n != x:
print(-1)
continue
if x == n:
print(n)
continue
s1 = bin(n)[2:]
s2 = bin(x)[2:]
s2 = "0" * (len(s1) - len(s2)) + s2
l = len(s1)
left10 = -1
right11 = l + 1
for i in range(l):
if s1[i] == "1" and s2[i] == "0":
left10 = l - 1 - i
break
for i in range(l - 1, -1, -1):
if s1[i] == "1" and s2[i] == "1":
right11 = l - 1 - i
break
if left10 == -1:
print(n)
continue
if right11 <= left10 + 1:
print(-1)
continue
z = 1 << left10 + 1
print((n & -z) + z)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
|
Petya and his friend, robot Petya++, like to solve exciting math problems.
One day Petya++ came up with the numbers $n$ and $x$ and wrote the following equality on the board: $$n\ \&\ (n+1)\ \&\ \dots\ \&\ m = x,$$ where $\&$ denotes the bitwise AND operation . Then he suggested his friend Petya find such a minimal $m$ ($m \ge n$) that the equality on the board holds.
Unfortunately, Petya couldn't solve this problem in his head and decided to ask for computer help. He quickly wrote a program and found the answer.
Can you solve this difficult problem?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2000$). The description of the test cases follows.
The only line of each test case contains two integers $n$, $x$ ($0\le n, x \le 10^{18}$).
-----Output-----
For every test case, output the smallest possible value of $m$ such that equality holds.
If the equality does not hold for any $m$, print $-1$ instead.
We can show that if the required $m$ exists, it does not exceed $5 \cdot 10^{18}$.
-----Examples-----
Input
5
10 8
10 10
10 42
20 16
1000000000000000000 0
Output
12
10
-1
24
1152921504606846976
-----Note-----
In the first example, $10\ \&\ 11 = 10$, but $10\ \&\ 11\ \&\ 12 = 8$, so the answer is $12$.
In the second example, $10 = 10$, so the answer is $10$.
In the third example, we can see that the required $m$ does not exist, so we have to print $-1$.
|
def solve():
n, x = map(int, input().split())
if n == x:
print(n)
return
for bitOff in range(70):
bit = 1 << bitOff
if not n & bit:
continue
tmpN = n
for smallOff in range(bitOff - 1, -1, -1):
smallBit = 1 << smallOff
if tmpN & smallBit:
tmpN ^= smallBit
tmpN += bit
result = n & tmpN
for smallOff in range(bitOff, -1, -1):
smallBit = 1 << smallOff
if result & smallBit:
result ^= smallBit
if result == x:
print(tmpN)
return
print(-1)
def main():
cases = int(input())
for _ in range(cases):
solve()
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with n vertexes. Each its edge has unit length. You should calculate the number of shortest paths between vertex 1 and vertex 2."
Same with some writers, she wants to make an example with some certain output: for example, her birthday or the number of her boyfriend. Can you help her to make a test case with answer equal exactly to k?
-----Input-----
The first line contains a single integer k (1 ≤ k ≤ 10^9).
-----Output-----
You should output a graph G with n vertexes (2 ≤ n ≤ 1000). There must be exactly k shortest paths between vertex 1 and vertex 2 of the graph.
The first line must contain an integer n. Then adjacency matrix G with n rows and n columns must follow. Each element of the matrix must be 'N' or 'Y'. If G_{ij} is 'Y', then graph G has a edge connecting vertex i and vertex j. Consider the graph vertexes are numbered from 1 to n.
The graph must be undirected and simple: G_{ii} = 'N' and G_{ij} = G_{ji} must hold. And there must be at least one path between vertex 1 and vertex 2. It's guaranteed that the answer exists. If there multiple correct answers, you can output any of them.
-----Examples-----
Input
2
Output
4
NNYY
NNYY
YYNN
YYNN
Input
9
Output
8
NNYYYNNN
NNNNNYYY
YNNNNYYY
YNNNNYYY
YNNNNYYY
NYYYYNNN
NYYYYNNN
NYYYYNNN
Input
1
Output
2
NY
YN
-----Note-----
In first example, there are 2 shortest paths: 1-3-2 and 1-4-2.
In second example, there are 9 shortest paths: 1-3-6-2, 1-3-7-2, 1-3-8-2, 1-4-6-2, 1-4-7-2, 1-4-8-2, 1-5-6-2, 1-5-7-2, 1-5-8-2.
|
k = int(input())
edges = [["N" for i in range(1010)] for j in range(1010)]
vertices = 2
def add_edge(a, b):
nonlocal edges
edges[a][b] = edges[b][a] = "Y"
for i in range(1, 29 + 1):
vertices += 3
add_edge(i * 3, i * 3 - 1)
add_edge(i * 3, i * 3 + 2)
add_edge(i * 3 + 1, i * 3 - 1)
add_edge(i * 3 + 1, i * 3 + 2)
for bit in range(30):
if 1 << bit & k:
lst = 1
for i in range((29 - bit) * 2):
vertices += 1
add_edge(lst, vertices)
lst = vertices
add_edge(lst, 3 * bit + 2)
print(vertices)
if 0:
for i in range(1, vertices + 1):
print(i, ":", "\n\t", end="")
for j in range(1, vertices + 1):
if edges[i][j] == "Y":
print(j, end=" ")
print("")
else:
print(
"\n".join(map(lambda x: "".join(x[1 : vertices + 1]), edges[1 : vertices + 1]))
)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
a, b = map(lambda s: bin(int(s))[2:], input().split())
a0, a1 = a + "1", a.rstrip("0")
if a == b or __import__("re").fullmatch(f"1*({a0}|{a1}|{a0[::-1]}|{a1[::-1]})1*", b):
print("YES")
else:
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR STRING FUNC_CALL VAR STRING IF VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING VAR STRING VAR STRING VAR NUMBER STRING VAR NUMBER STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
def check(a, b):
if a not in b:
return False
left = b[: b.find(a)]
right = b[b.find(a) + len(a) :]
if "0" in left or "0" in right:
return False
return True
x, y = map(int, input().split())
a = bin(x)[2:]
b = bin(y)[2:]
if a == b:
print("YES")
exit()
if check(a + "1", b) or check(a.strip("0"), b):
print("YES")
elif check((a + "1")[::-1], b) or check(a.strip("0")[::-1], b):
print("YES")
else:
print("NO")
|
FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF STRING VAR STRING VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR BIN_OP VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP VAR STRING NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
x, y = [int(i) for i in input().split(" ")]
ans = "NO"
if x == y:
print("YES")
exit(0)
bin_x, bin_y = str(bin(x))[2:], str(bin(y))[2:]
try:
i1 = bin_y.index(bin_x + "1")
re = set(bin_y[:i1] + bin_y[i1 + len(bin_x) + 1 :])
if len(re) == 0 or len(re) == 1 and "1" in re:
ans = "YES"
except:
pass
try:
i2 = bin_y.index((bin_x + "1")[::-1])
re = set(bin_y[:i2] + bin_y[i2 + len(bin_x) + 1 :])
if len(re) == 0 or len(re) == 1 and "1" in re:
ans = "YES"
except:
pass
bin_x = bin_x.strip("0")
try:
i3 = bin_y.index(bin_x)
re = set(bin_y[:i3] + bin_y[i3 + len(bin_x) :])
if len(re) == 0 or len(re) == 1 and "1" in re:
ans = "YES"
except:
pass
try:
i4 = bin_y.index(bin_x[::-1])
re = set(bin_y[:i4] + bin_y[i4 + len(bin_x) :])
if len(re) == 0 or len(re) == 1 and "1" in re:
ans = "YES"
except:
pass
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER STRING VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER STRING VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER STRING VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER STRING VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
def reverse(string):
string = string[::-1]
return string
def b(n):
return bin(n).replace("0b", "")
def z(a):
zeroes = 0
for i in a:
if i == "0":
zeroes += 1
return zeroes
x, y = map(int, input().split())
x, y = b(x), b(y)
if len(x) == len(y) and x in y:
print("YES")
elif x in y and z(x) == z(y) and (x[-1] == "0" and y[-1] == "0") == 0:
print("YES")
else:
x1, x2, x3, cnt = reverse(x), reverse(x + "1"), "", 0
for i in x1:
if i == "0":
cnt += 1
else:
break
x1 = x1[cnt:]
x3 = reverse(x1)
if len(x1) == len(y) and x1 in y:
print("YES")
elif len(x2) == len(y) and x2 in y:
print("YES")
elif len(x3) == len(y) and x3 in y:
print("YES")
elif x3 in y and z(x3) == z(y) and (x3[-1] == "0" and y[-1] == "0") == 0:
print("YES")
elif x1 in y and z(x1) == z(y) and (x1[-1] == "0" and y[-1] == "0") == 0:
print("YES")
elif x2 in y and z(x2) == z(y) and (x2[-1] == "0" and y[-1] == "0") == 0:
print("YES")
else:
print("NO")
|
FUNC_DEF ASSIGN VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR STRING STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER STRING VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR STRING STRING NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER STRING VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER STRING VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER STRING VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
a, b = map(int, input().split())
s = bin(b)[2:]
t = bin(a)[2:]
if s == t:
print("YES")
exit(0)
for q in [t + "1", t.strip("0")]:
for l in range(len(s) - len(q) + 1):
r = len(s) - len(q) - l
if "1" * l + q + "1" * r == s or "1" * l + q[::-1] + "1" * r == s:
print("YES")
exit(0)
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR LIST BIN_OP VAR STRING FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP BIN_OP STRING VAR VAR BIN_OP STRING VAR VAR BIN_OP BIN_OP BIN_OP STRING VAR VAR NUMBER BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
def debin(s):
ret = 0
mn = 1
for i in range(len(s) - 1, -1, -1):
ret += int(s[i]) * mn
mn *= 2
return ret
st = set()
def ch(x, y, deep):
if x in st:
return 0
st.add(x)
if x == y:
return 1
if deep == 150:
return 0
s = bin(x)[2:]
if ch(debin(s[::-1]), y, deep + 1) or ch(debin("1" + s[::-1]), y, deep + 1):
return 1
return 0
x, y = map(int, input().split())
if ch(x, y, 0):
print("YES")
else:
print("NO")
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP STRING VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
x, y = [str(bin(int(i)))[2:] for i in input().split()]
if x == y:
print("YES")
elif y[-1] == "0":
print("NO")
else:
x += "1"
if (y.find(x) != -1 or y.find(x[::-1]) != -1) and y.count("1") - x.count(
"1"
) == len(y) - len(x):
print("YES")
else:
x = x[:-1]
while x[-1] == "0":
x = x[:-1]
(
print("YES")
if (y.find(x) != -1 or y.find(x[::-1]) != -1)
and y.count("1") - x.count("1") == len(y) - len(x)
else print("NO")
)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER WHILE VAR NUMBER STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
import sys
v = set()
def bfs(n):
if n in v:
return
v.add(n)
if len(n) == len(bb):
if n == bb:
print("YES")
sys.exit(0)
elif n[0] == "1" and n[-1] == "1":
bfs(n[::-1])
return
elif len(n) > len(bb):
if n[0] == "1" and n[-1] == "1":
return
p1, p2 = n + "1", n + "0"
bfs(p1[::-1])
bfs(p2[::-1].lstrip("0"))
a, b = map(int, input().split())
if a == b:
print("YES")
else:
ba = bin(a)[2:]
bb = bin(b)[2:]
bfs(ba)
print("NO")
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER RETURN IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING VAR NUMBER STRING RETURN ASSIGN VAR VAR BIN_OP VAR STRING BIN_OP VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
def check(s, t):
idx = t.find(s)
if idx != -1:
lft = t[:idx]
rght = t[idx + len(s) :]
if lft.count("0") + rght.count("0") == 0:
return True
else:
return False
else:
return False
n, m = map(int, input().split())
sn = bin(n)[2:]
sm = bin(m)[2:]
if sn == sm:
print("YES")
exit()
if sn[-1] != "0":
sn_d = sn
if check(sn_d, sm):
print("YES")
exit()
sn_d = sn[::-1]
if check(sn_d, sm):
print("YES")
exit()
sn_d = sn + "1"
if check(sn_d, sm):
print("YES")
exit()
sn_d = "1" + sn[::-1]
if check(sn_d, sm):
print("YES")
exit()
sn_d = sn.rstrip("0")
if check(sn_d, sm):
print("YES")
exit()
sn_d = sn.rstrip("0")[::-1]
if check(sn_d, sm):
print("YES")
exit()
print("NO")
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING NUMBER RETURN NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR STRING IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
x, y = [int(i) for i in input().split(" ")]
def solve():
if x == y:
return True
a = bin(x)[2:]
b = bin(y)[2:]
if x == 0:
if b.count("0") == 1 and b[-1] != 0:
return True
else:
return False
n = len(a)
for i in range(n - 1, -1, -1):
if a[i] != "0":
c = a[: i + 1]
break
p = [a, "1" + a[::-1], c, c[::-1]]
def ck(aa, bb):
mm, nn = len(aa), len(bb)
if mm > nn:
return False
if mm == nn:
return aa == bb
if bb[-1] == "0":
return False
for i in range(nn - mm + 1):
if bb[i] == "0":
return False
if bb[i : i + mm] == aa:
if set(bb[i + mm :]) == set("1") or set(bb[i + mm :]) == set():
return True
return False
for i in p:
if ck(i, b):
return True
return False
if solve():
print("YES")
else:
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR STRING NUMBER VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR BIN_OP STRING VAR NUMBER VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR RETURN VAR VAR IF VAR NUMBER STRING RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR STRING RETURN NUMBER IF VAR VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR RETURN NUMBER RETURN NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
import sys
inpu = sys.stdin.readline
prin = sys.stdout.write
x, y = map(int, inpu().split())
if y == x:
print("YES")
exit()
x = bin(x)[2:]
y = bin(y)[2:]
ind = 0
for i in range(len(x)):
if x[i] == "1":
ind = i
use = x[: ind + 1]
if use in y:
ind = y.index(use)
if "0" not in y[:ind] and "0" not in y[ind + len(use) :]:
print("YES")
exit()
use = use[::-1]
if use in y:
ind = y.index(use)
if "0" not in y[:ind] and "0" not in y[ind + len(use) :]:
print("YES")
exit()
use = x + "1"
if use in y:
ind = y.index(use)
if "0" not in y[:ind] and "0" not in y[ind + len(use) :]:
print("YES")
exit()
use = use[::-1]
if use in y:
ind = y.index(use)
if "0" not in y[:ind] and "0" not in y[ind + len(use) :]:
print("YES")
exit()
print("NO")
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF STRING VAR VAR STRING VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF STRING VAR VAR STRING VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF STRING VAR VAR STRING VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF STRING VAR VAR STRING VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
def work(a, b, l, r):
for i in range(max(0, r - len(a)), min(l + 1, len(b) - len(a)) + 1):
if a == b[i : i + len(a)]:
print("YES")
exit(0)
[x, y] = map(int, input().split())
a, b, c = [1], [], []
while x:
a.append(x % 2)
c.append(x % 2)
x //= 2
while y:
b.append(y % 2)
y //= 2
if c == b:
print("YES")
exit(0)
c.reverse()
while c[-1] == 0:
c.pop()
l = -1
r = len(b)
while l + 1 < len(b) and b[l + 1] == 1:
l += 1
while r - 1 >= 0 and b[r - 1] == 1:
r -= 1
work(a, b, l, r)
a.reverse()
work(a, b, l, r)
work(c, b, l, r)
c.reverse()
work(c, b, l, r)
print("NO")
|
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN LIST VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR LIST NUMBER LIST LIST WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
L = input().split(" ")
s1 = str(bin(int(L[0])))[2:]
s2 = str(bin(int(L[1])))[2:]
n1 = 0
n2 = 0
for i in range(len(s1)):
if s1[i] == "0":
n1 += 1
for i in range(len(s2)):
if s2[i] == "0":
n2 += 1
if s1 == s2:
print("YES")
else:
if s1[-1] == "0":
if n1 == n2:
s1 += "1"
else:
while s1[-1] == "0":
n1 -= 1
s1 = s1[:-1]
if n1 != n2:
print("NO")
elif s2.find(s1) != -1 or s2.find(s1[::-1]) != -1:
print("YES")
else:
print("NO")
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER STRING IF VAR VAR VAR STRING WHILE VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
a, b = map(int, input().split())
sus = bin(int(bin(a)[2:][::-1], 2))[2:]
sussy = (bin(a)[2:] + "1")[::-1]
bb = bin(b)[2:]
realsus = sus[::-1]
realsussy = sussy[::-1]
amogus = bin(b)[2:]
great = True
pos = -1
leng = 0
for i in [sus, sussy, realsus, realsussy]:
lmao = False
pos = amogus.find(i)
leng = len(i)
if pos == -1:
lmao = True
if pos != -1:
c = bb[0:pos] + bb[pos + leng :]
for i in range(len(c)):
if c[i] != "1":
lmao = True
if lmao == False:
great = False
print("YES" if not great or a == b else "NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR LIST VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR STRING STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
def contain(a, b):
if not "0" in b:
if not "0" in a:
if len(a) <= len(b):
return True
return False
return False
if not "0" in a:
return False
listA = list(a)
listB = list(b)
Aleft = 0
Aright = 0
Bleft = 0
Bright = 0
while listA[0] == "1":
listA.remove("1")
Aleft += 1
while listA[-1] == "1":
listA.pop()
Aright += 1
while listB[0] == "1":
listB.remove("1")
Bleft += 1
while listB[-1] == "1":
listB.pop()
Bright += 1
reA = listA.copy()
reA.reverse()
return (
listA == listB
and Aleft <= Bleft
and Aright <= Bright
or reA == listB
and Aright <= Bleft
and Aleft <= Bright
)
def find(x, y):
a = bin(x)[2:]
b = bin(y)[2:]
if a == b:
return True
if a[-1] == "1":
return contain(a, b)
temp = list(a)
while temp[-1] == "0":
temp.pop()
aa = "".join(temp)
aaa = a + "1"
return contain(aa, b) or contain(aaa, b)
line = input().split()
x = int(line[0])
y = int(line[1])
if find(x, y):
print("YES")
else:
print("NO")
|
FUNC_DEF IF STRING VAR IF STRING VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER RETURN NUMBER IF STRING VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER STRING EXPR FUNC_CALL VAR STRING VAR NUMBER WHILE VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER STRING EXPR FUNC_CALL VAR STRING VAR NUMBER WHILE VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR RETURN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR RETURN NUMBER IF VAR NUMBER STRING RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP VAR STRING RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
x, y = map(int, input().split())
used = set()
s = [x]
f = False
for _ in range(10000):
if len(s) == 0:
break
a = s[0]
del s[0]
if a == y:
f = True
break
b = bin(a).lstrip("0b")
y1 = int("0b" + (b + "0")[::-1], 2)
y2 = int("0b" + (b + "1")[::-1], 2)
if y1 == y or y2 == y:
f = True
break
if y1 not in used:
used.add(y1)
s.append(y1)
if y2 not in used:
used.add(y2)
s.append(y2)
if f:
print("YES")
else:
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR STRING NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR STRING NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
import sys
input = sys.stdin.readline
x, y = map(int, input().split())
if x == y:
ans = "YES"
print(ans)
exit()
x = list(bin(x)[2:])
y = list(bin(y)[2:])
x.append("1")
lx, ly = len(x), len(y)
ans = "NO"
for _ in range(2):
for i in range(max(0, ly - lx + 1)):
ok = 1
for j in range(lx):
if not x[j] == y[i + j]:
ok = 0
break
if not ok:
continue
for j in range(i):
if y[j] == "0":
ok = 0
for j in range(i + lx, ly):
if y[j] == "0":
ok = 0
if ok:
ans = "YES"
x.reverse()
x.pop()
while x[-1] == "0":
x.pop()
lx = len(x)
for _ in range(2):
for i in range(max(0, ly - lx + 1)):
ok = 1
for j in range(lx):
if not x[j] == y[i + j]:
ok = 0
break
if not ok:
continue
for j in range(i):
if y[j] == "0":
ok = 0
for j in range(i + lx, ly):
if y[j] == "0":
ok = 0
if ok:
ans = "YES"
x.reverse()
print(ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR WHILE VAR NUMBER STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
from sys import stdin, stdout
x, y = [int(z) for z in stdin.readline().split()]
answer = "NO"
if x == y:
answer = "YES"
x_reduced = x
while x_reduced % 2 == 0:
x_reduced = x_reduced // 2
y_bin = str(bin(y))[2:]
x_reduced_bin = str(bin(x_reduced))[2:]
if len(x_reduced_bin) <= len(y_bin):
delta = len(y_bin) - len(x_reduced_bin)
for i in range(delta + 1):
candidate = "1" * i + x_reduced_bin + "1" * (delta - i)
if candidate == y_bin:
answer = "YES"
x_reduced_bin = x_reduced_bin[::-1]
if len(x_reduced_bin) <= len(y_bin):
delta = len(y_bin) - len(x_reduced_bin)
for i in range(delta + 1):
candidate = "1" * i + x_reduced_bin + "1" * (delta - i)
if candidate == y_bin:
answer = "YES"
x_reduced_bin = str(bin(x))[2:] + "1"
if len(x_reduced_bin) <= len(y_bin):
delta = len(y_bin) - len(x_reduced_bin)
for i in range(delta + 1):
candidate = "1" * i + x_reduced_bin + "1" * (delta - i)
if candidate == y_bin:
answer = "YES"
x_reduced_bin = x_reduced_bin[::-1]
if len(x_reduced_bin) <= len(y_bin):
delta = len(y_bin) - len(x_reduced_bin)
for i in range(delta + 1):
candidate = "1" * i + x_reduced_bin + "1" * (delta - i)
if candidate == y_bin:
answer = "YES"
stdout.write(answer + "\n")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING IF VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR VAR BIN_OP STRING BIN_OP VAR VAR IF VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR VAR BIN_OP STRING BIN_OP VAR VAR IF VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR VAR BIN_OP STRING BIN_OP VAR VAR IF VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR VAR BIN_OP STRING BIN_OP VAR VAR IF VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
a, b = [int(i) for i in input().split(" ")]
a = bin(a)[2:]
b = bin(b)[2:]
good = lambda a, b: b.replace(a, "", 1) == (len(b) - len(a)) * "1"
check = a == b
check = check or good(a + "1", b)
check = check or good((a + "1")[::-1], b)
while a[-1] == "0":
a = a[:-1]
check = check or good(a, b)
check = check or good(a[::-1], b)
if check:
print("YES")
else:
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR STRING VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR STRING NUMBER VAR WHILE VAR NUMBER STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
a, b = map(int, input().split())
st = bin(a)[2:]
ed = bin(b)[2:]
if st == ed:
print("YES")
exit(0)
s1 = st + "1"
s2 = st.strip("0")
for s in [s1, s2, s1[::-1], s2[::-1]]:
for l in range(len(ed)):
r = len(ed) - len(s) - l
if r < 0:
continue
if "1" * l + s + "1" * r == ed:
print("YES")
exit(0)
print("NO")
exit(0)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR LIST VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF BIN_OP BIN_OP BIN_OP STRING VAR VAR BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
x, y = map(int, input().split())
if x == y:
print("YES")
exit(0)
s1, s2 = list(bin(x)[2:]), bin(y)[2:]
s3 = bin(x)[2:]
r_s3 = s3[::-1]
while s1[-1] == "0":
s1.pop()
s1 = "".join(s1)
r_s1 = s1[::-1]
for i in range(len(s2) - len(s1) + 1):
if (
s2[i : i + len(s1)] == s1
and s2[:i].count("0") == 0
and s2[i + len(s1) :].count("0") == 0
):
print("YES")
exit(0)
if (
s2[i : i + len(s1)] == r_s1
and s2[:i].count("0") == 0
and s2[i + len(s1) :].count("0") == 0
):
print("YES")
exit(0)
if s3 != s1:
for i in range(len(s2) - len(s3) + 1):
if (
s2[i : i + len(s3)] == s3
and s2[:i].count("0") == 0
and s2[i + len(s3) :].count("0") == 0
):
if s2[i + len(s3) :].count("1") != 0:
print("YES")
exit(0)
if (
s2[i : i + len(s3)] == r_s3
and s2[:i].count("0") == 0
and s2[i + len(s3) :].count("0") == 0
):
print("YES")
exit(0)
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR NUMBER STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR STRING NUMBER FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR STRING NUMBER FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR STRING NUMBER FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR STRING NUMBER IF FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR STRING NUMBER FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
x, y = map(int, input().split())
def check(x, y):
b1, b2 = bin(x)[2:], bin(y)[2:]
n = len(b2)
if y == x:
return True
c1 = (b1 + "1")[::-1]
c2 = b1[::-1].lstrip("0")
c3 = c1[::-1]
c4 = c2[::-1]
for cand in [c1, c2, c3, c4]:
m = len(cand)
if m > n:
continue
for i in range(n - m + 1):
if (
b2[i : i + m] == cand
and b2[:i].count("0") == 0
and b2[i + m :].count("0") == 0
):
return True
return False
ans = check(x, y)
if ans:
print("YES")
else:
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR LIST VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR STRING NUMBER FUNC_CALL VAR BIN_OP VAR VAR STRING NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
x, y = map(int, input().split())
s = set()
s.add(x)
a = [x]
for u in a:
if u > 10**20:
continue
k = 2 * u + 0
b = bin(k)[2:][::-1]
v = int(b, 2)
if v not in s:
s.add(v)
a.append(v)
k = 2 * u + 1
b = bin(k)[2:][::-1]
v = int(b, 2)
if v not in s:
s.add(v)
a.append(v)
print("YES" if y in s else "NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FOR VAR VAR IF VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
def solver():
first_num, second_num = map(int, input().split())
if first_num == second_num:
print("YES")
return 0
base_2_first_num_rev = ""
base_2_second_num_rev = ""
def div_mod2(a):
return a // 2, a % 2
while first_num > 0:
first_num, coef = div_mod2(first_num)
base_2_first_num_rev += str(coef)
while second_num > 0:
second_num, coef = div_mod2(second_num)
base_2_second_num_rev += str(coef)
base_2_first_num, base_2_second_num = (
base_2_first_num_rev[::-1],
base_2_second_num_rev[::-1],
)
if base_2_second_num[-1] == "0":
print("NO")
return 0
n = len(base_2_first_num)
n_1 = len(base_2_second_num) - n
for i in range(n_1 + 1):
check = base_2_second_num[i : i + n]
not_until_now = base_2_second_num[i + n :]
until_now = base_2_second_num[:i]
if check == base_2_first_num_rev or check == base_2_first_num:
if not ("0" in until_now or "0" in not_until_now):
print("YES")
return 0
while base_2_first_num[-1] == "0":
base_2_first_num = base_2_first_num[:-1]
base_2_first_num_rev = base_2_first_num_rev[1:]
n = len(base_2_first_num)
n_1 = len(base_2_second_num) - n
for i in range(n_1 + 1):
check = base_2_second_num[i : i + n]
not_until_now = base_2_second_num[i + n :]
until_now = base_2_second_num[:i]
if check == base_2_first_num_rev or check == base_2_first_num:
if not ("0" in until_now or "0" in not_until_now):
print("YES")
return 0
print("NO")
return 0
solver()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF RETURN BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING RETURN NUMBER WHILE VAR NUMBER STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING RETURN NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER EXPR FUNC_CALL VAR
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
a, b = list(map(int, input().strip().split()))
a_str = "{0:b}".format(a)
b_str = "{0:b}".format(b)
a_str_1 = a_str + "1"
a_str_rev = a_str[::-1].strip("0")
a_str_rev_1 = a_str_1[::-1].strip("0")
a_strs = [a_str.strip("0"), a_str_1, a_str_rev, a_str_rev_1]
ans = a_str == b_str
for string in a_strs:
pos = b_str.find(string)
if pos == -1:
continue
b = b_str[:pos] + b_str[pos + len(string) :]
if b == "1" * len(b):
ans = True
break
print("YES" if ans else "NO")
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR NUMBER STRING ASSIGN VAR LIST FUNC_CALL VAR STRING VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR BIN_OP STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
import sys
input = sys.stdin.readline
def removeLeadingZeors(x):
index = len(x)
for i in range(len(x)):
if x[i] == "1":
index = i
break
return x[index:]
def reverse(x):
return x[::-1]
def sumString(x):
ans = 0
for i in x:
ans += int(i)
return ans
def solve(x, y):
if x == y:
return True
x = removeLeadingZeors(bin(x)[2:])
y = bin(y)[2:]
test = set()
temp = removeLeadingZeors(reverse(x))
test.add(temp)
test.add(reverse(temp))
temp = reverse(x + "1")
test.add(temp)
test.add(reverse(temp))
lengthY = len(y)
for i in test:
temp = y.find(i)
if temp != -1:
length = len(i)
if lengthY - length == sumString(y[:temp]) + sumString(y[temp + length :]):
return True
return False
x, y = map(int, input().split())
if solve(x, y):
print("YES")
else:
print("NO")
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF RETURN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
def check_candidate(y, candidate):
if candidate in y:
a = set(list(y.replace(candidate, "", 1)))
if len(a) == 1 and "1" in a:
return True
return False
def slv(x, y):
if x == y:
return "YES"
candidates = set()
candidates.add(x + "1")
candidates.add(x.rstrip("0"))
if y in candidates or y[::-1] in candidates:
return "YES"
for candidate in candidates:
if check_candidate(y, candidate):
return "YES"
if check_candidate(y, candidate[::-1]):
return "YES"
return "NO"
x, y = [int(_) for _ in input().rstrip().split(" ")]
y = bin(y)[2:]
x = bin(x)[2:]
print(slv(x, y))
|
FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING NUMBER IF FUNC_CALL VAR VAR NUMBER STRING VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING IF VAR VAR VAR NUMBER VAR RETURN STRING FOR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN STRING IF FUNC_CALL VAR VAR VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
def solve(current, target):
queue = [current]
visited = set()
while len(queue):
currentNode = queue.pop(0)
currentIdx = 0
while currentNode[currentIdx] == "0":
currentIdx += 1
currentNode = currentNode[currentIdx:]
if currentNode in visited:
continue
visited.add(currentNode)
if currentNode == target:
return "YES"
newStringOne, newStringTwo = currentNode, currentNode + "1"
if len(currentNode) <= len(target):
queue.append(newStringTwo[::-1])
queue.append(newStringOne[::-1])
return "NO"
x, y = map(int, input().split())
result = solve("{0:b}".format(x), "{0:b}".format(y))
print(result)
|
FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR RETURN STRING ASSIGN VAR VAR VAR BIN_OP VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
def check(s1, s2):
index = s2.find(s1)
return (
False
if index == -1
else s2 == "1" * index + s1 + "1" * (len(s2) - index - len(s1))
)
x, y = map(int, input().split())
if y % 2 == 0:
print("YES" if y == x else "NO")
elif x % 2:
print(
"YES"
if check(bin(x)[2:], bin(y)[2:]) or check(bin(x)[2:][::-1], bin(y)[2:])
else "NO"
)
else:
a = check(bin(x)[2:] + "1", bin(y)[2:]) or check(
(bin(x)[2:] + "1")[::-1], bin(y)[2:]
)
xb = bin(x)[2:]
while xb[-1] == "0":
xb = xb[:-1]
b = check(xb, bin(y)[2:]) or check(xb[::-1], bin(y)[2:])
print("YES" if a or b else "NO")
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP STRING VAR VAR BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR STRING STRING IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER STRING STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER STRING ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
x, y = [int(x) for x in input().split()]
if x == y:
print("YES")
exit()
a, b = bin(x), bin(y)
a = a.replace("0b", "")
b = b.replace("0b", "")
if b[-1] == "0":
print("NO")
exit()
if a in b and a.count("0") == b.count("0"):
print("YES")
exit()
b = b[::-1]
if a in b and a.count("0") == b.count("0"):
print("YES")
exit()
while a[-1] == "0":
a = a[: len(a) - 1]
if a in b and a.count("0") == b.count("0"):
print("YES")
exit()
b = b[::-1]
if a in b and a.count("0") == b.count("0"):
print("YES")
else:
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR WHILE VAR NUMBER STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
def sol(t, s):
pos = t.find(s)
while pos != -1:
x = t[:pos]
y = t[pos + len(s) :]
if "0" not in x and "0" not in y:
return True
pos = t.find(s, pos + 1)
return False
def solve():
[x, y] = [int(a) for a in input().split()]
if x == y:
print("YES")
return
s = list(bin(x)[2:])
t = bin(y)[2:]
s1 = list(bin(x)[2:])
while s1[-1] == "0":
s1.pop()
s2 = None
if s[-1] == "0":
s2 = s
s2.append("1")
if sol(t, "".join(s1)):
print("YES")
return
if s2 is not None and sol(t, "".join(s2)):
print("YES")
return
s3 = [x for x in s1]
s3.reverse()
if s2 is not None:
s4 = [x for x in s2]
else:
s4 = None
if sol(t, "".join(s3)):
print("YES")
return
if s4 is not None:
s4.reverse()
if s4 is not None and sol(t, "".join(s4)):
print("YES")
return
print("NO")
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR FUNC_CALL VAR VAR IF STRING VAR STRING VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER STRING EXPR FUNC_CALL VAR ASSIGN VAR NONE IF VAR NUMBER STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING RETURN IF VAR NONE FUNC_CALL VAR VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR IF VAR NONE ASSIGN VAR VAR VAR VAR ASSIGN VAR NONE IF FUNC_CALL VAR VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING RETURN IF VAR NONE EXPR FUNC_CALL VAR IF VAR NONE FUNC_CALL VAR VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
def check(a, b):
if a[-1] == "0":
return False
rev = a[::-1]
for i in range(len(b) - len(a) + 1):
if rev == b[i : i + len(a)] or a == b[i : i + len(a)]:
j, k, valid = i, i + len(a), True
while j >= 0:
if b[j] == "0":
valid = False
break
j -= 1
while k < len(b):
if b[k] == "0":
valid = False
break
k += 1
if valid:
return True
return False
a, b = map(int, input().split())
a, b = bin(a)[2:], bin(b)[2:]
if a == b or a + "1" == b or check(a, b) or check(a + "1", b) or check(a.strip("0"), b):
print("YES")
else:
print("NO")
|
FUNC_DEF IF VAR NUMBER STRING RETURN NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
def f(s, y):
if s in y:
i = y.index(s)
for j in range(0, i):
if y[j] != "1":
return False
for j in range(i + len(s), len(y)):
if y[j] != "1":
return False
return True
return False
x, y = map(int, input().split())
x = bin(x)[2:]
y = bin(y)[2:]
i = 0
j = x.rfind("1")
s = x[i : j + 1]
s1 = s[::-1]
s3 = x + "1"
s4 = s3[::-1]
if x == y or f(s, y) or f(s1, y) or f(s3, y) or f(s4, y):
print("YES")
else:
print("NO")
|
FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING RETURN NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
x, y = map(int, input().split())
x = str(bin(x))[2:]
y = str(bin(y))[2:]
x1, x2 = x.rstrip("0"), x + "1"
if x == y or __import__("re").fullmatch(f"1*({x1}|{x2}|{x1[::-1]}|{x2[::-1]})1*", y):
print("YES")
else:
print("NO")
|
ASSIGN VAR VAR FUNC_CALL 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 VAR FUNC_CALL VAR STRING BIN_OP VAR STRING IF VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING VAR STRING VAR STRING VAR NUMBER STRING VAR NUMBER STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
def check(first, second):
idx = second.find(first)
if idx == -1:
return False
return "0" not in second[:idx] and "0" not in second[idx + len(first) :]
def solve(x, y):
if x == y:
return True
x_bin = bin(x)[2:]
y_bin = bin(y)[2:]
first = "1" + x_bin[::-1]
second = x_bin[: x_bin.rfind("1") + 1]
return any(check(s, y_bin) for s in [first, first[::-1], second, second[::-1]])
x, y = map(int, input().split())
print("YES" if solve(x, y) else "NO")
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER RETURN STRING VAR VAR STRING VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR STRING NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR LIST VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
a, b = map(int, input().split())
a = str(bin(a)[2:])
b = str(bin(b)[2:])
if b[-1] == "0" and a != b:
print("NO")
exit()
elif a == b:
print("YES")
exit()
x1 = ""
flag = False
for el in a[::-1]:
if el == "1":
flag = True
x1 += el
if el == "0":
if flag:
x1 += el
x2 = "1" + a[::-1]
if x1 in b:
y1 = b[: b.find(x1)] + b[b.find(x1) + len(x1) :]
if y1.count("0") == 0:
print("YES")
exit()
x1 = x1[::-1]
if x1 in b:
y1 = b[: b.find(x1)] + b[b.find(x1) + len(x1) :]
if y1.count("0") == 0:
print("YES")
exit()
x1 = x2
if x1 in b:
y1 = b[: b.find(x1)] + b[b.find(x1) + len(x1) :]
if y1.count("0") == 0:
print("YES")
exit()
x1 = x1[::-1]
if x1 in b:
y1 = b[: b.find(x1)] + b[b.find(x1) + len(x1) :]
if y1.count("0") == 0:
print("YES")
exit()
print("NO")
|
ASSIGN VAR VAR FUNC_CALL 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 IF VAR NUMBER STRING VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER VAR VAR IF VAR STRING IF VAR VAR VAR ASSIGN VAR BIN_OP STRING VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
a, b = map(int, input().split())
x = bin(a)[2:]
y = bin(b)[2:]
def add0(s):
while s[-1] == "0":
s = s[0 : len(s) - 1]
return s[::-1]
def add1(s):
s += "1"
return s[::-1]
v = []
check = []
v.append(x)
check.append(x)
ans = False
while len(v) > 0:
t = v[0]
del v[0]
if t == y:
ans = True
break
else:
q = add0(t)
if len(q) < 65 and q not in check:
v.append(q)
check.append(q)
q = add1(t)
if len(q) < 65 and q not in check:
v.append(q)
check.append(q)
if ans:
print("YES")
else:
print("NO")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF WHILE VAR NUMBER STRING ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER FUNC_DEF VAR STRING RETURN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
def check(s: str, t: str):
index = s.find(t)
return (
False if index == -1 else s == "1" * index + t + "1" * (len(s) - index - len(t))
)
def CF_760(x, y):
if x == y:
return True
if y % 2 == 0:
return False
binX = bin(x)[2:]
binY = bin(y)[2:]
if x % 2:
return check(binY, binX) or check(binY, binX[::-1])
binXbina0 = binX[: binX.rfind("1") + 1]
return (
check(binY, binX)
or check(binY, binX[::-1])
or check(binY, binXbina0)
or check(binY, binXbina0[::-1])
)
print("YES" if CF_760(*map(int, input().split())) else "NO")
|
FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP STRING VAR VAR BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR STRING NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING
|
You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is assigned as the new value of $x$.
For example:
$34$ can be turned into $81$ via one operation: the binary form of $34$ is $100010$, if you add $1$, reverse it and remove leading zeros, you will get $1010001$, which is the binary form of $81$.
$34$ can be turned into $17$ via one operation: the binary form of $34$ is $100010$, if you add $0$, reverse it and remove leading zeros, you will get $10001$, which is the binary form of $17$.
$81$ can be turned into $69$ via one operation: the binary form of $81$ is $1010001$, if you add $0$, reverse it and remove leading zeros, you will get $1000101$, which is the binary form of $69$.
$34$ can be turned into $69$ via two operations: first you turn $34$ into $81$ and then $81$ into $69$.
Your task is to find out whether $x$ can be turned into $y$ after a certain number of operations (possibly zero).
-----Input-----
The only line of the input contains two integers $x$ and $y$ ($1 \le x, y \le 10^{18}$).
-----Output-----
Print YES if you can make $x$ equal to $y$ and NO if you can't.
-----Examples-----
Input
3 3
Output
YES
Input
7 4
Output
NO
Input
2 8
Output
NO
Input
34 69
Output
YES
Input
8935891487501725 71487131900013807
Output
YES
-----Note-----
In the first example, you don't even need to do anything.
The fourth example is described in the statement.
|
def prov(z, x):
l = len(x)
m = len(z)
e = 0
for i in range(l - m + 1):
if z == x[i : m + i]:
e = 1
x = x[:i] + x[m + i :]
break
if e == 1:
for i in x:
if i == "0":
e = -1
break
return e
a = []
x, y = map(int, input().split())
z = str(bin(x))[2:]
zz = z + "1"
while z[-1] == "0":
z = z[:-1]
a.append(z)
a.append(zz)
a.append(zz[::-1])
a.append(z[::-1])
v = str(bin(y))[2:]
t = 0
for i in a:
if prov(i, v) == 1:
t = 1
break
if x == y:
print("YES")
elif t == 1:
print("YES")
else:
print("NO")
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING WHILE VAR NUMBER STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
N, Q = [int(x) for x in input().strip().split(" ")]
A = int(input(), 2)
B = int(input(), 2)
s = ""
for q in range(0, Q):
a = input().split(" ")
if a[0] == "set_a":
mask = 1 << int(a[1])
if a[2] == "1":
A |= mask
else:
A &= ~mask
elif a[0] == "set_b":
mask = 1 << int(a[1])
if a[2] == "1":
B |= mask
else:
B &= ~mask
else:
mask = 1 << int(a[1])
if A + B & mask:
s += "1"
else:
s += "0"
print(s)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER STRING ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
length, queries = input().strip().split(" ")
length = int(length)
a = int(input().strip(), 2)
b = int(input().strip(), 2)
output = ""
for i in range(int(queries)):
line = input().split(" ")
q = line[0]
index = int(line[1])
if q == "set_a":
bit = int(line[2])
val = 1 << index
a = a | val if bit else a & ~val
elif q == "set_b":
bit = int(line[2])
val = 1 << index
b = b | val if bit else b & ~val
else:
c = a + b
output += "1" if c & 1 << index else "0"
print(output)
|
ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR STRING STRING EXPR FUNC_CALL VAR VAR
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
n, q = input().split()
n, q = int(n), int(q)
result = ""
if n >= 1 and n <= 100000 and q >= 1 and q <= 500000:
a = input()
if len(a) == n:
b = input()
if len(b) == n:
a = int(a, 2)
b = int(b, 2)
for i in range(q):
command = input().split()
if command[0] == "set_a":
num = 1 << int(command[1])
if int(command[2]):
a = a | num
else:
a = a & ~num
elif command[0] == "set_b":
num = 1 << int(command[1])
if int(command[2]):
b = b | num
else:
b = b & ~num
else:
c = a + b
result += str(int(bool(c & 1 << int(command[1]))))
print(result)
|
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
import sys
def main():
parameters = input().split()
bitLength = int(parameters[0])
numQueries = int(parameters[1])
numA = int(input(), 2)
numB = int(input(), 2)
for queryNum in range(numQueries):
query = input().split()
command = query[0]
index = int(query[1])
if command == "set_a":
set = query[2]
if set == "1":
numA = setBit(numA, index)
else:
numA = clearBit(numA, index)
elif command == "set_b":
set = query[2]
if set == "1":
numB = setBit(numB, index)
else:
numB = clearBit(numB, index)
elif command == "get_c":
bit = testBit(numA + numB, index)
sys.stdout.write(bit)
def testBit(number, offset):
mask = 1 << offset
if number & mask:
return "1"
else:
return "0"
def setBit(number, offset):
mask = 1 << offset
return number | mask
def clearBit(number, offset):
mask = ~(1 << offset)
return number & mask
main()
|
IMPORT FUNC_DEF ASSIGN 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 FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR RETURN STRING RETURN STRING FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR RETURN BIN_OP VAR VAR EXPR FUNC_CALL VAR
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
n, q = [int(x) for x in input().strip().split(" ")]
a = int(input().strip(), 2)
b = int(input().strip(), 2)
def set_bit(num, idx, val):
mask = 1 << idx
return num | mask if val else num & ~mask
for i in range(q):
line = input().strip().split(" ")
idx = int(line[1])
if len(line) == 2:
print(a + b >> idx & 1, end="")
else:
val = int(line[2])
if line[0] == "set_a":
a = set_bit(a, idx, val)
else:
b = set_bit(b, idx, val)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR RETURN VAR BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
N, Q = list(map(int, input().split()))
A = int(input(), 2)
B = int(input(), 2)
result = []
all_ones = 2**N - 1
def get_c(x):
C = A + B
return ["0", "1"][C >> int(x) & 1]
temp = ""
for i in range(Q):
s = input().split()
if s[0] == "set_a":
idx, bit = int(s[1]), int(s[2])
if bit:
A |= 1 << idx
else:
A &= ~(1 << idx)
elif s[0] == "set_b":
idx, bit = int(s[1]), int(s[2])
if bit:
B |= 1 << idx
else:
B &= ~(1 << idx)
elif s[0] == "get_c":
result.append(get_c(s[1]))
print("".join(result))
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR RETURN LIST STRING STRING BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
import sys
n, q = list(map(int, input().split()))
a = input()
b = input()
c = int(a, 2) + int(b, 2)
a = list(reversed(a))
b = list(reversed(b))
for i in range(q):
s = input().split()
idx = int(s[1])
if len(s) == 2:
bl = 1 << idx
sys.stdout.write(c & bl and "1" or "0")
else:
p = s[0][4]
nb = s[2]
if p == "a":
cb = a[idx]
if cb != nb:
a[idx] = nb
if nb == "1":
c += 1 << idx
else:
c -= 1 << idx
else:
cb = b[idx]
if cb != nb:
b[idx] = nb
if nb == "1":
c += 1 << idx
else:
c -= 1 << idx
|
IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR STRING STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR IF VAR STRING VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR IF VAR STRING VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
def setbit(val, i, bit):
num = 1 << i
if bit:
return val | num
return val & ~num
n, q = map(int, input().strip().split(" "))
a = int(input().strip(), 2)
b = int(input().strip(), 2)
out = ""
for i in range(q):
cmd = input().strip().split(" ")
inx = int(cmd[1])
cmd.append(7)
bit = int(cmd[2])
if cmd[0] == "set_a":
a = setbit(a, inx, bit)
elif cmd[0] == "set_b":
b = setbit(b, inx, bit)
else:
cdec = a + b
cbit = not not cdec & 1 << inx
out += str(int(cbit))
print(out)
|
FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR IF VAR RETURN BIN_OP VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
test = tuple(map(int, input().strip().split(" ")))
def setbit(a, b, c):
n = 1 << int(b)
if c == "1":
return a | n
return a & ~n
a = int(input().strip(), 2)
b = int(input().strip(), 2)
s = ""
for t in range(test[1]):
r = input().strip().split(" ")
if r[0] == "set_a":
a = setbit(a, r[1], r[2])
elif r[0] == "set_b":
b = setbit(b, r[1], r[2])
else:
c = a + b
cbit = int(bool(c & 1 << int(r[1])))
s = s + str(cbit)
print(s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR STRING RETURN BIN_OP VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
n, q = map(int, input().split())
a = int(input(), 2)
b = int(input(), 2)
def set_bit(v, index, on):
b = 1 << index
return v | b if on else v & ~b
for _ in range(q):
k, *args = input().split()
args = list(map(int, args))
if k == "set_a":
a = set_bit(a, *args)
elif k == "set_b":
b = set_bit(b, *args)
elif k == "get_c":
print(a + b >> args[0] & 1, end="")
print("")
|
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR RETURN VAR BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR STRING
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
def set_bit(n, offset):
mask = 1 << offset
return n | mask
def clear_bit(n, offset):
mask = ~(1 << offset)
return n & mask
def get_bit(n, i):
mask = 1 << i
return 1 if n & mask else 0
line = input("").split(" ")
N, Q = int(line[0]), int(line[1])
A = int(input(""), 2)
B = int(input(""), 2)
output = []
for __ in range(Q):
line = input("").split(" ")
if line[0] == "set_a":
idx, x = int(line[1]), int(line[2])
A = set_bit(A, idx) if x else clear_bit(A, idx)
elif line[0] == "set_b":
idx, x = int(line[1]), int(line[2])
B = set_bit(B, idx) if x else clear_bit(B, idx)
else:
idx = int(line[1])
output.append(get_bit(A + B, idx))
print("".join(str(b) for b in output))
|
FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR RETURN BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING IF VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
n_bit, line_count = [int(i) for i in input().split()]
a = int(input(), 2)
b = int(input(), 2)
for i in range(line_count):
inp = input().split()
x = int(inp[1])
if inp[0] == "get_c":
print((a + b & 1 << x) >> x, end="")
elif inp[0] == "set_a":
if inp[2] == "1":
a = a | 1 << x
else:
a = a & ~(1 << x)
elif inp[2] == "1":
b = b | 1 << x
else:
b = b & ~(1 << x)
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR STRING IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
N, Q = [int(s) for s in input().split(" ")]
A = int(input(), 2)
B = int(input(), 2)
C = None
for _ in range(Q):
line = input().split()
if line[0] == "get_c":
if C is None:
C = A + B
idx = int(line[1])
print(C >> idx & 1, end="")
else:
C = None
idx, x = [int(s) for s in line[1:]]
V = B
if line[0] == "set_a":
V = A
bit = 1 << idx
if x == 1:
V |= bit
else:
V = ~(~V | bit)
if line[0] == "set_a":
A = V
else:
B = V
print()
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING IF VAR NONE ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR NONE ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
N, Q = [int(x) for x in input().strip().split()]
A = int(input().strip(), 2)
B = int(input().strip(), 2)
Output = []
for dummyQ in range(Q):
QueryFields = input().strip().split()
if QueryFields[0] == "set_a":
idx, x = [int(x) for x in QueryFields[1:]]
Target = A >> idx & 1
if Target != x:
A ^= 1 << idx
if QueryFields[0] == "set_b":
idx, x = [int(x) for x in QueryFields[1:]]
Target = B >> idx & 1
if Target != x:
B ^= 1 << idx
if QueryFields[0] == "get_c":
idx = int(QueryFields[1])
Value = A + B >> idx & 1
Output.append(str(Value))
print("".join(Output))
|
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
def find_base(N):
M = 2
while M < N:
M <<= 1
return M
def build(X):
XC = ["0"] * (2 * M)
MM = M >> 1
XC[M : M + N] = X
for i in range(M - 1, 0, -1):
if i < M and i >= MM:
XC[i] = int(XC[i << 1]) + int(XC[i << 1 | 1])
else:
XC[i] = XC[i << 1] + XC[i << 1 | 1]
return XC
def modify_xi(XC, idx):
l = M + N - 1 - idx
XC[l] = str(int(XC[l]) ^ 1)
q = l
l >>= 1
XC[l] = int(XC[q]) + int(XC[q ^ 1])
while l > 1:
q = l
l >>= 1
XC[l] = XC[q] + XC[q ^ 1]
return XC
def inter_of(l):
ln2 = l << 1 | 1
ln1 = ln2 ^ 1
while ln1 < M:
ln1 <<= 1
ln2 = ln2 << 1 | 1
bigInt = int("".join([item for item in segt_A[ln1 : ln2 + 1]]), 2)
bigInt += int("".join([item for item in segt_B[ln1 : ln2 + 1]]), 2)
bigL = 1 << ln2 - ln1 + 1
if bigInt >= bigL:
return 1
elif bigInt < bigL - 1:
return 0
else:
return 2
def query_of(pos):
l, num = pos, 1
while l > 0:
p = min(num, N)
if num == 1:
a = int(segt_A[l])
b = int(segt_B[l])
else:
a = segt_A[l]
b = segt_B[l]
val = a + b
if (a == p or b == p) and val > p:
return 1
if a * b == 0 and val < p:
return 0
if a * b == 0 and val == p:
pass
elif a > 0 and b > 0 and p > 1:
big = inter_of(l)
if big < 2:
return big
if l in [1, 3]:
return 0
if num == limBig or l > l ^ 1:
l += 1
else:
l >>= 1
num <<= 1
return 0
def getC(idx):
if idx > N or idx < 0:
return 0
pos = M + N - 1 - idx
carry = 0
if idx > 0:
carry = query_of(pos + 1)
if idx < N:
val = int(segt_A[pos]) + int(segt_B[pos]) + carry
else:
val = carry
return str(val % 2)
N, Q = [int(t) for t in input().split()]
A = [c for c in input().strip()]
B = [c for c in input().strip()]
ans, limBig, M = "", 2048, find_base(N)
segt_A, segt_B = build(A), build(B)
for i in range(Q):
lin1 = input().split()
idx = int(lin1[1])
if lin1[0][0] == "s":
bit = lin1[2]
if lin1[0][4] == "a" and bit != A[N - 1 - idx]:
modify_xi(segt_A, idx)
A[N - 1 - idx] = bit
elif lin1[0][4] == "b" and bit != B[N - 1 - idx]:
modify_xi(segt_B, idx)
B[N - 1 - idx] = bit
else:
ans += getC(idx)
print(ans)
|
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST STRING BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR RETURN NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR RETURN NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR IF VAR LIST NUMBER NUMBER RETURN NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR STRING NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER STRING ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER STRING VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER NUMBER STRING VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
import sys
n = [int(number) for number in input().split()]
a = int(input(), 2)
b = int(input(), 2)
for i in range(n[1]):
query = input().split()
if query[0] == "set_a":
if query[2] == "0":
a &= ~(1 << int(query[1]))
elif query[2] == "1":
a |= 1 << int(query[1])
elif query[0] == "set_b":
if query[2] == "0":
b &= ~(1 << int(query[1]))
elif query[2] == "1":
b |= 1 << int(query[1])
elif query[0] == "get_c":
x = a + b & 1 << int(query[1])
print(x >> int(query[1]), end="", sep="")
|
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING IF VAR NUMBER STRING VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING IF VAR NUMBER STRING VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER STRING STRING
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
raw = input().split()
n = int(raw[0])
q = int(raw[1])
a = int(input(), 2)
b = int(input(), 2)
c = a + b
for i in range(q):
qraw = input().split()
if qraw[0] == "set_a":
idx = int(qraw[1])
x = int(qraw[2])
if a >> idx & 1 != x:
if x == 1:
a = a | 1 << idx
else:
a = a & ~(1 << idx)
c = a + b
elif qraw[0] == "set_b":
idx = int(qraw[1])
x = int(qraw[2])
if b >> idx & 1 != x:
if x == 1:
b = b | 1 << idx
else:
b = b & ~(1 << idx)
c = a + b
else:
idx = int(qraw[1])
d = c >> idx & 1
print(d, end="")
|
ASSIGN 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 FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
def clearBit(n, pos):
return n & ~(1 << pos)
def setBit(n, pos):
return n | 1 << pos
def getBit(n, pos):
return 0 if n & 1 << pos == 0 else 1
n, q = input().split()
n, q = int(n), int(q)
a = int(input(), 2)
b = int(input(), 2)
buf = []
for _ in range(q):
cmd = input().split()
pos = int(cmd[1])
if cmd[0] == "set_a":
a = clearBit(a, pos) if cmd[2] == "0" else setBit(a, pos)
elif cmd[0] == "set_b":
b = clearBit(b, pos) if cmd[2] == "0" else setBit(b, pos)
else:
c = a + b
buf.append(getBit(c, pos))
print("".join([str(x) for x in buf]))
|
FUNC_DEF RETURN BIN_OP VAR BIN_OP NUMBER VAR FUNC_DEF RETURN BIN_OP VAR BIN_OP NUMBER VAR FUNC_DEF RETURN BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR VAR NUMBER STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR VAR NUMBER STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
Let a and b be binary numbers of length n (MSB to the left). The following commands may be performed:
set_a idx x: Set $a[i dx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $a[i dx]$ is $\text{id}x^{\text{th}}$ least significant bit of $a$.
set_b idx x: Set $b[idx]$ to $\boldsymbol{x}$, where $0\leq idx<n$ and $b[idx]$ is $\text{id}x^{\text{th}}$ least significant bit of $\boldsymbol{b}$.
get_c idx: Print $c[idx]$, where $c[idx]=a[idx]+b[idx]$ and $0\leq idx\leq n+1$.
Given $a,b$, and a list of commands, create a string made of the results of each $\text{get_c}$ call, the only command that produces output. For example, $\boldsymbol{a}=\boldsymbol{000}$ and $b=111$ so the length of the numbers is $n=3$. Print an answer string that contains the results of all commands on one line. A series of commands and their results follow:
Starting
ans = '' (empty string)
a b
000 111
set_a 1 1
010 111
set_b 0 1
010 111
get_c 3
a + b = 1001
ans = '1'
010 111
get_c 4
a + b = 01001
ans = '10'
Note: When the command is get_c 4, $\textbf{C}$ had to be padded to the left with a $0$ to be long enough to return a value.
Function Description
Complete the changeBits function in the editor below. For each get_c command, it should print either a 0 or a 1 without a newline until all commands have been processed. At that point, add a newline.
changeBits has the following parameters:
- a, b: two integers represented as binary strings
- queries[queries[0]-queries[n-1]]: an array of query strings in the format described
Input Format
The first line of input contains two space-separated integers, $n$ and $\textit{q}$, the length of the binary representations of $a$ and $\boldsymbol{b}$, and the number of commands, respectively.
The second and third lines each contain a string representation of $a$ and $\boldsymbol{b}$.
The following $\textit{q}$ lines each contain a command string $\textit{queries}[i]$ as described above.
Constraints
$1\leq n\leq1000000$
$1\leq q\leq5000000$
Output Format
For each query of the type $\text{get_c}$, output a single digit 0 or 1. Output must be placed on a single line.
Sample Input 0
5 5
00000
11111
set_a 0 1
get_c 5
get_c 1
set_b 2 0
get_c 5
Sample Output 0
100
Explanation 0
set_a 0 1 sets 00000 to 00001
C = A + B = 00001 + 11111 = 100000, so get_c[5] = 1
from the above computation get_c[1] = 0
set_b 2 0 sets 11111 to 11011
C = A + B = 00001 + 11011 = 011100, so get_c[5] = 0
The output is hence concatenation of 1, 0 and 0 = 100
|
T = list(map(int, input().split()))
A = int(input(), 2)
B = int(input(), 2)
for _ in range(T[1]):
temp = input()
if temp[4] == "a":
if temp[-1] == "1":
A = A | 1 << int(temp[5:-2])
else:
A = A & ~(1 << int(temp[5:-2]))
elif temp[4] == "b":
if temp[-1] == "1":
B = B | 1 << int(temp[5:-2])
else:
B = B & ~(1 << int(temp[5:-2]))
else:
print((A + B & 1 << int(temp[5:])) >> int(temp[5:]), end="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER STRING IF VAR NUMBER STRING ASSIGN VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER STRING
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.