description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given non-negative integers A, B and C. Does there exist a non-negative integer X such that A \oplus X+ B \oplus X = C \oplus X? As a reminder, \oplus denotes the [bitwise XOR operation]. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - The only line of each test case contains three space-separated non-negative integers A, B and C. ------ Output Format ------ For each test case, print on a new line the answer: YES if valid X exists, and NO otherwise. Each character of the output may be printed in either uppercase or lowercase, i.e, the strings Yes, YES, yes, yEs will all be treated as identical. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ A, B, C < 2^{27}$ ----- Sample Input 1 ------ 5 2 5 7 2 3 13 7 0 7 2 7 6 1 6 6 ----- Sample Output 1 ------ YES NO YES YES YES ----- explanation 1 ------ Test case $1$: $X=0$ satisfies the equation. Test case $2$: It can be proved that there does not exist a non-negative integer $X$ which satisfies the equation. Test case $3$: $X=0$ satisfies the equation. Test case $4$: $X=3$ satisfies the equation. Test case $5$: $X=1$ satisfies the equation.
for _ in range(int(input())): a, b, c = map(int, input().split()) i = 0 con = 0 while i < 28: x = a & 1 y = b & 1 z = c & 1 if x == y and x != z: con = con + 1 i = i + 1 a = a >> 1 b = b >> 1 c = c >> 1 if con % 2: print("NO") else: print("YES")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given non-negative integers A, B and C. Does there exist a non-negative integer X such that A \oplus X+ B \oplus X = C \oplus X? As a reminder, \oplus denotes the [bitwise XOR operation]. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - The only line of each test case contains three space-separated non-negative integers A, B and C. ------ Output Format ------ For each test case, print on a new line the answer: YES if valid X exists, and NO otherwise. Each character of the output may be printed in either uppercase or lowercase, i.e, the strings Yes, YES, yes, yEs will all be treated as identical. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ A, B, C < 2^{27}$ ----- Sample Input 1 ------ 5 2 5 7 2 3 13 7 0 7 2 7 6 1 6 6 ----- Sample Output 1 ------ YES NO YES YES YES ----- explanation 1 ------ Test case $1$: $X=0$ satisfies the equation. Test case $2$: It can be proved that there does not exist a non-negative integer $X$ which satisfies the equation. Test case $3$: $X=0$ satisfies the equation. Test case $4$: $X=3$ satisfies the equation. Test case $5$: $X=1$ satisfies the equation.
def getBitSum(a, b, carry): return a ^ b ^ carry def getCarry(a, b, carry): return (a & b) + (carry & (a ^ b)) def getIthBit(x, i): return x >> i & 1 t = int(input()) while t: t -= 1 a, b, c = map(int, input().split()) result = 0 possibleSum = 0 possibleSumWithXor = 0 carry = 0 ai, bi, ci = 0, 0, 0 aix, bix, cix = 0, 0, 0 for i in range(27): ai = getIthBit(a, i) bi = getIthBit(b, i) ci = getIthBit(c, i) possibleSum = getBitSum(ai ^ 0, bi ^ 0, carry) aix = ai ^ 1 bix = bi ^ 1 cix = ci ^ 1 possibleSumWithXor = getBitSum(aix, bix, carry) if possibleSum == ci: carry = getCarry(ai, bi, carry) elif possibleSumWithXor == cix: carry = getCarry(aix, bix, carry) result = result | 1 << i else: break if carry == 0: print("YES") else: print("NO")
FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given non-negative integers A, B and C. Does there exist a non-negative integer X such that A \oplus X+ B \oplus X = C \oplus X? As a reminder, \oplus denotes the [bitwise XOR operation]. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - The only line of each test case contains three space-separated non-negative integers A, B and C. ------ Output Format ------ For each test case, print on a new line the answer: YES if valid X exists, and NO otherwise. Each character of the output may be printed in either uppercase or lowercase, i.e, the strings Yes, YES, yes, yEs will all be treated as identical. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ A, B, C < 2^{27}$ ----- Sample Input 1 ------ 5 2 5 7 2 3 13 7 0 7 2 7 6 1 6 6 ----- Sample Output 1 ------ YES NO YES YES YES ----- explanation 1 ------ Test case $1$: $X=0$ satisfies the equation. Test case $2$: It can be proved that there does not exist a non-negative integer $X$ which satisfies the equation. Test case $3$: $X=0$ satisfies the equation. Test case $4$: $X=3$ satisfies the equation. Test case $5$: $X=1$ satisfies the equation.
t = int(input()) for _ in range(t): a, b, c = map(int, input().split()) bina = str(bin(a))[2:] binb = str(bin(b))[2:] binc = str(bin(c))[2:] lena = len(bina) lenb = len(binb) lenc = len(binc) n = max([lena, lenb, lenc]) bina = (n - lena) * "0" + bina binb = (n - lenb) * "0" + binb binc = (n - lenc) * "0" + binc bina = bina[::-1] binb = binb[::-1] binc = binc[::-1] carry = 0 for i in range(n): if carry == 0: if bina[i] == binb[i] and binb[i] == binc[i] or bina[i] != binb[i]: continue else: carry = 1 elif bina[i] == binb[i] and bina[i] != binc[i]: carry = 0 continue elif bina[i] == binb[i] and binb[i] == binc[i]: continue elif bina[i] != binb[i]: continue if carry == 0: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR STRING VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given non-negative integers A, B and C. Does there exist a non-negative integer X such that A \oplus X+ B \oplus X = C \oplus X? As a reminder, \oplus denotes the [bitwise XOR operation]. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - The only line of each test case contains three space-separated non-negative integers A, B and C. ------ Output Format ------ For each test case, print on a new line the answer: YES if valid X exists, and NO otherwise. Each character of the output may be printed in either uppercase or lowercase, i.e, the strings Yes, YES, yes, yEs will all be treated as identical. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ A, B, C < 2^{27}$ ----- Sample Input 1 ------ 5 2 5 7 2 3 13 7 0 7 2 7 6 1 6 6 ----- Sample Output 1 ------ YES NO YES YES YES ----- explanation 1 ------ Test case $1$: $X=0$ satisfies the equation. Test case $2$: It can be proved that there does not exist a non-negative integer $X$ which satisfies the equation. Test case $3$: $X=0$ satisfies the equation. Test case $4$: $X=3$ satisfies the equation. Test case $5$: $X=1$ satisfies the equation.
for _ in range(int(input())): a, b, c = map(int, input().split()) carry = 0 for i in range(30): v1 = a >> i & 1 v2 = b >> i & 1 v3 = c >> i & 1 for x in range(2): if (v1 ^ x) + (v2 ^ x) + carry & 1 == v3 ^ x: carry = int((v1 ^ x) + (v2 ^ x) + carry > 1) break if carry: print("NO") else: print("YES")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given non-negative integers A, B and C. Does there exist a non-negative integer X such that A \oplus X+ B \oplus X = C \oplus X? As a reminder, \oplus denotes the [bitwise XOR operation]. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - The only line of each test case contains three space-separated non-negative integers A, B and C. ------ Output Format ------ For each test case, print on a new line the answer: YES if valid X exists, and NO otherwise. Each character of the output may be printed in either uppercase or lowercase, i.e, the strings Yes, YES, yes, yEs will all be treated as identical. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ A, B, C < 2^{27}$ ----- Sample Input 1 ------ 5 2 5 7 2 3 13 7 0 7 2 7 6 1 6 6 ----- Sample Output 1 ------ YES NO YES YES YES ----- explanation 1 ------ Test case $1$: $X=0$ satisfies the equation. Test case $2$: It can be proved that there does not exist a non-negative integer $X$ which satisfies the equation. Test case $3$: $X=0$ satisfies the equation. Test case $4$: $X=3$ satisfies the equation. Test case $5$: $X=1$ satisfies the equation.
def has_ans(a, b, c, s): if a == 0 and b == 0 and c == 0: return s == 0 next_bit = 0 if ((next_bit ^ a) + (next_bit ^ b)) % 2 != ((c ^ next_bit) + s) % 2: next_bit = 1 s += -(a % 2 ^ next_bit) - (b % 2 ^ next_bit) + (c % 2 ^ next_bit) s /= 2 return has_ans(int(a / 2), int(b / 2), int(c / 2), s) t = int(input()) for t0 in range(t): a, b, c = list(map(int, input().split())) if has_ans(a, b, c, 0): print("YES") else: print("NO")
FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given non-negative integers A, B and C. Does there exist a non-negative integer X such that A \oplus X+ B \oplus X = C \oplus X? As a reminder, \oplus denotes the [bitwise XOR operation]. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - The only line of each test case contains three space-separated non-negative integers A, B and C. ------ Output Format ------ For each test case, print on a new line the answer: YES if valid X exists, and NO otherwise. Each character of the output may be printed in either uppercase or lowercase, i.e, the strings Yes, YES, yes, yEs will all be treated as identical. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ A, B, C < 2^{27}$ ----- Sample Input 1 ------ 5 2 5 7 2 3 13 7 0 7 2 7 6 1 6 6 ----- Sample Output 1 ------ YES NO YES YES YES ----- explanation 1 ------ Test case $1$: $X=0$ satisfies the equation. Test case $2$: It can be proved that there does not exist a non-negative integer $X$ which satisfies the equation. Test case $3$: $X=0$ satisfies the equation. Test case $4$: $X=3$ satisfies the equation. Test case $5$: $X=1$ satisfies the equation.
def ans(a, b, c): x = "" carry = 0 for i in range(0, len(bin(max(a, b, c))) - 2): ai = a >> i & 1 bi = b >> i & 1 ci = c >> i & 1 if ai == bi == ci == 1: if carry == 0: x += "1" else: x += "0" elif ai == bi == ci == 0: if carry == 0: x += "0" else: x += "1" elif ai != bi and ci == 0: if carry == 0: x += "1" else: x += "0" elif ai != bi and ci == 1: if carry == 0: x += "0" else: x += "1" elif ai == bi == 1 and ci == 0: if carry == 0: carry = 1 x += "0" else: x += "1" carry = 0 elif carry == 0: x += "1" carry = 1 else: carry = 0 x += "0" x = x[::-1] x = int(x, 2) if (a ^ x) + (b ^ x) == c ^ x: return "YES" return "NO" test_cases = int(input()) while test_cases != 0: d = list(map(int, input().split())) print(ans(d[0], d[1], d[2])) test_cases -= 1
FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR NUMBER VAR STRING VAR STRING IF VAR VAR VAR NUMBER IF VAR NUMBER VAR STRING VAR STRING IF VAR VAR VAR NUMBER IF VAR NUMBER VAR STRING VAR STRING IF VAR VAR VAR NUMBER IF VAR NUMBER VAR STRING VAR STRING IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR STRING VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER
You are given non-negative integers A, B and C. Does there exist a non-negative integer X such that A \oplus X+ B \oplus X = C \oplus X? As a reminder, \oplus denotes the [bitwise XOR operation]. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - The only line of each test case contains three space-separated non-negative integers A, B and C. ------ Output Format ------ For each test case, print on a new line the answer: YES if valid X exists, and NO otherwise. Each character of the output may be printed in either uppercase or lowercase, i.e, the strings Yes, YES, yes, yEs will all be treated as identical. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ A, B, C < 2^{27}$ ----- Sample Input 1 ------ 5 2 5 7 2 3 13 7 0 7 2 7 6 1 6 6 ----- Sample Output 1 ------ YES NO YES YES YES ----- explanation 1 ------ Test case $1$: $X=0$ satisfies the equation. Test case $2$: It can be proved that there does not exist a non-negative integer $X$ which satisfies the equation. Test case $3$: $X=0$ satisfies the equation. Test case $4$: $X=3$ satisfies the equation. Test case $5$: $X=1$ satisfies the equation.
t = int(input()) def possible(a, b, c, carry): if a + b + c == 0: return carry == 0 ax = a % 2 bx = b % 2 cx = c % 2 if (ax + bx + carry) % 2 == cx: if possible(a >> 1, b >> 1, c >> 1, (ax + bx + carry) // 2): return True if (1 - ax + 1 - bx + carry) % 2 == 1 - cx: if possible(a >> 1, b >> 1, c >> 1, (1 - ax + 1 - bx + carry) // 2): return True return False for _ in range(t): a, b, c = map(int, input().split()) print("YES" if possible(a, b, c, 0) else "NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN NUMBER IF BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER STRING STRING
You are given non-negative integers A, B and C. Does there exist a non-negative integer X such that A \oplus X+ B \oplus X = C \oplus X? As a reminder, \oplus denotes the [bitwise XOR operation]. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - The only line of each test case contains three space-separated non-negative integers A, B and C. ------ Output Format ------ For each test case, print on a new line the answer: YES if valid X exists, and NO otherwise. Each character of the output may be printed in either uppercase or lowercase, i.e, the strings Yes, YES, yes, yEs will all be treated as identical. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ A, B, C < 2^{27}$ ----- Sample Input 1 ------ 5 2 5 7 2 3 13 7 0 7 2 7 6 1 6 6 ----- Sample Output 1 ------ YES NO YES YES YES ----- explanation 1 ------ Test case $1$: $X=0$ satisfies the equation. Test case $2$: It can be proved that there does not exist a non-negative integer $X$ which satisfies the equation. Test case $3$: $X=0$ satisfies the equation. Test case $4$: $X=3$ satisfies the equation. Test case $5$: $X=1$ satisfies the equation.
def get_bin(n): l = [(0) for _ in range(28)] for i in range(1, 28): l[-i] = n % 2 n //= 2 return l for _ in range(int(input())): a, b, c = map(int, input().split()) a1, b1, c1 = get_bin(a), get_bin(b), get_bin(c) car = 0 for i in range(1, 28): if a1[-i] == b1[-i] and c1[-i] != b1[-i]: car = not car if car: print("NO") else: print("YES")
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given non-negative integers A, B and C. Does there exist a non-negative integer X such that A \oplus X+ B \oplus X = C \oplus X? As a reminder, \oplus denotes the [bitwise XOR operation]. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - The only line of each test case contains three space-separated non-negative integers A, B and C. ------ Output Format ------ For each test case, print on a new line the answer: YES if valid X exists, and NO otherwise. Each character of the output may be printed in either uppercase or lowercase, i.e, the strings Yes, YES, yes, yEs will all be treated as identical. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ A, B, C < 2^{27}$ ----- Sample Input 1 ------ 5 2 5 7 2 3 13 7 0 7 2 7 6 1 6 6 ----- Sample Output 1 ------ YES NO YES YES YES ----- explanation 1 ------ Test case $1$: $X=0$ satisfies the equation. Test case $2$: It can be proved that there does not exist a non-negative integer $X$ which satisfies the equation. Test case $3$: $X=0$ satisfies the equation. Test case $4$: $X=3$ satisfies the equation. Test case $5$: $X=1$ satisfies the equation.
t = int(input()) while t: a, b, c = map(int, input().split()) k = 0 for i in range(28): x, y, z = a >> i & 1, b >> i & 1, c >> i & 1 if x == y and y != z: k ^= 1 if k: print("NO") else: print("YES") t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER
You are given non-negative integers A, B and C. Does there exist a non-negative integer X such that A \oplus X+ B \oplus X = C \oplus X? As a reminder, \oplus denotes the [bitwise XOR operation]. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - The only line of each test case contains three space-separated non-negative integers A, B and C. ------ Output Format ------ For each test case, print on a new line the answer: YES if valid X exists, and NO otherwise. Each character of the output may be printed in either uppercase or lowercase, i.e, the strings Yes, YES, yes, yEs will all be treated as identical. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ A, B, C < 2^{27}$ ----- Sample Input 1 ------ 5 2 5 7 2 3 13 7 0 7 2 7 6 1 6 6 ----- Sample Output 1 ------ YES NO YES YES YES ----- explanation 1 ------ Test case $1$: $X=0$ satisfies the equation. Test case $2$: It can be proved that there does not exist a non-negative integer $X$ which satisfies the equation. Test case $3$: $X=0$ satisfies the equation. Test case $4$: $X=3$ satisfies the equation. Test case $5$: $X=1$ satisfies the equation.
t = int(input()) for _ in range(t): a, b, c = list(map(int, input().split())) ba = bin(a)[2:] bb = bin(b)[2:] bc = bin(c)[2:] m = max(len(ba), len(bb), len(bc)) ba = "0" * (m - len(ba)) + ba bb = "0" * (m - len(bb)) + bb bc = "0" * (m - len(bc)) + bc ba = ba[::-1] bb = bb[::-1] bc = bc[::-1] c = 0 for i in range(len(ba)): ua = int(ba[i]) ub = int(bb[i]) uc = int(bc[i]) f = c + ua + ub r = f % 2 c = f // 2 if r != uc: ua = (ua + 1) % 2 ub = (ub + 1) % 2 uc = (uc + 1) % 2 f = c + ua + ub c = f // 2 if c == 1: ans = "NO" else: ans = "YES" print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL 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 FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
You are given non-negative integers A, B and C. Does there exist a non-negative integer X such that A \oplus X+ B \oplus X = C \oplus X? As a reminder, \oplus denotes the [bitwise XOR operation]. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - The only line of each test case contains three space-separated non-negative integers A, B and C. ------ Output Format ------ For each test case, print on a new line the answer: YES if valid X exists, and NO otherwise. Each character of the output may be printed in either uppercase or lowercase, i.e, the strings Yes, YES, yes, yEs will all be treated as identical. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ A, B, C < 2^{27}$ ----- Sample Input 1 ------ 5 2 5 7 2 3 13 7 0 7 2 7 6 1 6 6 ----- Sample Output 1 ------ YES NO YES YES YES ----- explanation 1 ------ Test case $1$: $X=0$ satisfies the equation. Test case $2$: It can be proved that there does not exist a non-negative integer $X$ which satisfies the equation. Test case $3$: $X=0$ satisfies the equation. Test case $4$: $X=3$ satisfies the equation. Test case $5$: $X=1$ satisfies the equation.
def soln(a, b, c): def form(s): return "0" * (32 - len(s)) + s a = form(bin(a)[2:]) b = form(bin(b)[2:]) c = form(bin(c)[2:]) count = 0 for i in range(31, 0, -1): if a[i] == b[i] and a[i] != c[i]: count += 1 return "YES" if not count & 1 else "NO" for _ in range(int(input())): a, b, c = map(int, input().split()) print(soln(a, b, c))
FUNC_DEF FUNC_DEF RETURN BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
You are given non-negative integers A, B and C. Does there exist a non-negative integer X such that A \oplus X+ B \oplus X = C \oplus X? As a reminder, \oplus denotes the [bitwise XOR operation]. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - The only line of each test case contains three space-separated non-negative integers A, B and C. ------ Output Format ------ For each test case, print on a new line the answer: YES if valid X exists, and NO otherwise. Each character of the output may be printed in either uppercase or lowercase, i.e, the strings Yes, YES, yes, yEs will all be treated as identical. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ A, B, C < 2^{27}$ ----- Sample Input 1 ------ 5 2 5 7 2 3 13 7 0 7 2 7 6 1 6 6 ----- Sample Output 1 ------ YES NO YES YES YES ----- explanation 1 ------ Test case $1$: $X=0$ satisfies the equation. Test case $2$: It can be proved that there does not exist a non-negative integer $X$ which satisfies the equation. Test case $3$: $X=0$ satisfies the equation. Test case $4$: $X=3$ satisfies the equation. Test case $5$: $X=1$ satisfies the equation.
def solve(a, b, c): carry = 0 for i in range(28): if a & 1 == b & 1 and b & 1 != c & 1: carry ^= 1 a >>= 1 b >>= 1 c >>= 1 if carry: return False return True t = int(input()) for _ in range(t): a, b, c = [int(x) for x in input().split()] ans = solve(a, b, c) if ans: print("YES") else: print("NO")
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given non-negative integers A, B and C. Does there exist a non-negative integer X such that A \oplus X+ B \oplus X = C \oplus X? As a reminder, \oplus denotes the [bitwise XOR operation]. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - The only line of each test case contains three space-separated non-negative integers A, B and C. ------ Output Format ------ For each test case, print on a new line the answer: YES if valid X exists, and NO otherwise. Each character of the output may be printed in either uppercase or lowercase, i.e, the strings Yes, YES, yes, yEs will all be treated as identical. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ A, B, C < 2^{27}$ ----- Sample Input 1 ------ 5 2 5 7 2 3 13 7 0 7 2 7 6 1 6 6 ----- Sample Output 1 ------ YES NO YES YES YES ----- explanation 1 ------ Test case $1$: $X=0$ satisfies the equation. Test case $2$: It can be proved that there does not exist a non-negative integer $X$ which satisfies the equation. Test case $3$: $X=0$ satisfies the equation. Test case $4$: $X=3$ satisfies the equation. Test case $5$: $X=1$ satisfies the equation.
for _ in range(int(input())): a, b, c = map(int, input().split()) a, b, c = bin(a)[2:], bin(b)[2:], bin(c)[2:] m = max(len(a), len(b), len(c)) a = "0" * (m - len(a)) + a b = "0" * (m - len(b)) + b c = "0" * (m - len(c)) + c f = 0 ans = True for i in range(m): if a[i] + b[i] + c[i] == "001" or a[i] + b[i] + c[i] == "110": f += 1 if f % 2 == 1: ans = False if ans: print("YES") continue print("NO")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR STRING BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given non-negative integers A, B and C. Does there exist a non-negative integer X such that A \oplus X+ B \oplus X = C \oplus X? As a reminder, \oplus denotes the [bitwise XOR operation]. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - The only line of each test case contains three space-separated non-negative integers A, B and C. ------ Output Format ------ For each test case, print on a new line the answer: YES if valid X exists, and NO otherwise. Each character of the output may be printed in either uppercase or lowercase, i.e, the strings Yes, YES, yes, yEs will all be treated as identical. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ A, B, C < 2^{27}$ ----- Sample Input 1 ------ 5 2 5 7 2 3 13 7 0 7 2 7 6 1 6 6 ----- Sample Output 1 ------ YES NO YES YES YES ----- explanation 1 ------ Test case $1$: $X=0$ satisfies the equation. Test case $2$: It can be proved that there does not exist a non-negative integer $X$ which satisfies the equation. Test case $3$: $X=0$ satisfies the equation. Test case $4$: $X=3$ satisfies the equation. Test case $5$: $X=1$ satisfies the equation.
def s(a, b, c): r = 0 for i in range(28): x, y, z = a >> i & 1, b >> i & 1, c >> i & 1 if x == y and y != z: r ^= 1 return r t = int(input()) for i in range(t): a, b, c = map(int, input().split()) p = s(a, b, c) if p: print("NO") else: print("YES")
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Monisha likes to paint. She has painted $N$ paintings (numbered $1$ through $N$) and wants to choose some subset of these paintings for an exhibition. For each valid $i$, the $i$-th painting has beauty $b_i$ and the probability that it will be displayed at the exhibition is $p_i$. Each painting is chosen or excluded from the exhibition independently randomly. The beauty of the resulting exhibition is the bitwise XOR of the beauties of all displayed paintings. If no paintings are displayed, the XOR is $0$. Monisha wants to find out how beautiful her exhibition is going to be. Help her compute the expected value of the beauty of the exhibition. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $b_1, b_2, \ldots, b_N$. - The third line contains $N$ space-separated real numbers $p_1, p_2, \ldots, p_N$. Each of these numbers is given with at most five digits after the decimal point. -----Output----- For each test case, print a single line containing one real number — the expected beauty of the exhibition. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. -----Constraints----- - $1 \le N \le 10^5$ - $0 \le b_i \le 10^9$ for each valid $i$ - $0 \le p_i \le 1$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $4 \cdot 10^5$ -----Example Input----- 2 3 5 6 2 1.0 0.0 0.5 4 2 2 2 2 0.5 0.5 0.5 0.5 -----Example Output----- 6.000000000000000 1.000000000000000 -----Explanation----- Example case 1: The first painting must be displayed at the exhibition, the second one must be excluded. If the third painting is displayed (with probability $0.5$), the beauty is $5 \oplus 2 = 7$; if it is excluded (with probability $0.5$), the beauty is $5$. The expected beauty is $0.5 \cdot 5 + 0.5 \cdot 7 = 6$. Example case 2: If there is an odd number of paintings at the exhibition, the beauty is $2$; this has a probability of $0.5$. If there is an even number of paintings, the beauty is $0$ (with probability $0.5$), so the expected beauty is $0.5 \cdot 0 + 0.5 \cdot 2 = 1$.
k = 30 for _ in range(int(input())): n = int(input()) l1 = list(map(int, input().split())) l2 = list(map(float, input().split())) ans = 0 for i in range(k): p = 0 for j in range(n): if l1[j] & 1 << i: p = p * (1 - l2[j]) + (1 - p) * l2[j] ans += p * (1 << i) print("%.15f" % ans)
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
Monisha likes to paint. She has painted $N$ paintings (numbered $1$ through $N$) and wants to choose some subset of these paintings for an exhibition. For each valid $i$, the $i$-th painting has beauty $b_i$ and the probability that it will be displayed at the exhibition is $p_i$. Each painting is chosen or excluded from the exhibition independently randomly. The beauty of the resulting exhibition is the bitwise XOR of the beauties of all displayed paintings. If no paintings are displayed, the XOR is $0$. Monisha wants to find out how beautiful her exhibition is going to be. Help her compute the expected value of the beauty of the exhibition. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $b_1, b_2, \ldots, b_N$. - The third line contains $N$ space-separated real numbers $p_1, p_2, \ldots, p_N$. Each of these numbers is given with at most five digits after the decimal point. -----Output----- For each test case, print a single line containing one real number — the expected beauty of the exhibition. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. -----Constraints----- - $1 \le N \le 10^5$ - $0 \le b_i \le 10^9$ for each valid $i$ - $0 \le p_i \le 1$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $4 \cdot 10^5$ -----Example Input----- 2 3 5 6 2 1.0 0.0 0.5 4 2 2 2 2 0.5 0.5 0.5 0.5 -----Example Output----- 6.000000000000000 1.000000000000000 -----Explanation----- Example case 1: The first painting must be displayed at the exhibition, the second one must be excluded. If the third painting is displayed (with probability $0.5$), the beauty is $5 \oplus 2 = 7$; if it is excluded (with probability $0.5$), the beauty is $5$. The expected beauty is $0.5 \cdot 5 + 0.5 \cdot 7 = 6$. Example case 2: If there is an odd number of paintings at the exhibition, the beauty is $2$; this has a probability of $0.5$. If there is an even number of paintings, the beauty is $0$ (with probability $0.5$), so the expected beauty is $0.5 \cdot 0 + 0.5 \cdot 2 = 1$.
l = [1] for k in range(31): l.append(l[-1] * 2) def convert(s): while len(s) != 32: s = "0" + s ans = "" for i in s: ans = i + ans return ans def main(): for _ in range(int(input())): n = int(input()) val = list(map(int, input().split())) p = list(map(float, input().split())) res = 0 for i in range(32): x = 0 for j in range(n): if val[j] & 1 << i: x = p[j] * (1 - x) + (1 - p[j]) * x res += l[i] * x print("%.6f" % res) main()
ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR
Monisha likes to paint. She has painted $N$ paintings (numbered $1$ through $N$) and wants to choose some subset of these paintings for an exhibition. For each valid $i$, the $i$-th painting has beauty $b_i$ and the probability that it will be displayed at the exhibition is $p_i$. Each painting is chosen or excluded from the exhibition independently randomly. The beauty of the resulting exhibition is the bitwise XOR of the beauties of all displayed paintings. If no paintings are displayed, the XOR is $0$. Monisha wants to find out how beautiful her exhibition is going to be. Help her compute the expected value of the beauty of the exhibition. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $b_1, b_2, \ldots, b_N$. - The third line contains $N$ space-separated real numbers $p_1, p_2, \ldots, p_N$. Each of these numbers is given with at most five digits after the decimal point. -----Output----- For each test case, print a single line containing one real number — the expected beauty of the exhibition. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. -----Constraints----- - $1 \le N \le 10^5$ - $0 \le b_i \le 10^9$ for each valid $i$ - $0 \le p_i \le 1$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $4 \cdot 10^5$ -----Example Input----- 2 3 5 6 2 1.0 0.0 0.5 4 2 2 2 2 0.5 0.5 0.5 0.5 -----Example Output----- 6.000000000000000 1.000000000000000 -----Explanation----- Example case 1: The first painting must be displayed at the exhibition, the second one must be excluded. If the third painting is displayed (with probability $0.5$), the beauty is $5 \oplus 2 = 7$; if it is excluded (with probability $0.5$), the beauty is $5$. The expected beauty is $0.5 \cdot 5 + 0.5 \cdot 7 = 6$. Example case 2: If there is an odd number of paintings at the exhibition, the beauty is $2$; this has a probability of $0.5$. If there is an even number of paintings, the beauty is $0$ (with probability $0.5$), so the expected beauty is $0.5 \cdot 0 + 0.5 \cdot 2 = 1$.
for i in range(int(input())): n = int(input()) b = list(map(int, input().split())) p = list(map(float, input().split())) ans = 0 o = [0] * 30 for i in range(n): s = bin(b[i])[2:] for j in range(1, len(s) + 1): if s[-j] == "1": o[j - 1] = (1 - o[j - 1]) * p[i] + (1 - p[i]) * o[j - 1] ans = 0 x = 1 for item in o: ans += x * item x = x * 2 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Monisha likes to paint. She has painted $N$ paintings (numbered $1$ through $N$) and wants to choose some subset of these paintings for an exhibition. For each valid $i$, the $i$-th painting has beauty $b_i$ and the probability that it will be displayed at the exhibition is $p_i$. Each painting is chosen or excluded from the exhibition independently randomly. The beauty of the resulting exhibition is the bitwise XOR of the beauties of all displayed paintings. If no paintings are displayed, the XOR is $0$. Monisha wants to find out how beautiful her exhibition is going to be. Help her compute the expected value of the beauty of the exhibition. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $b_1, b_2, \ldots, b_N$. - The third line contains $N$ space-separated real numbers $p_1, p_2, \ldots, p_N$. Each of these numbers is given with at most five digits after the decimal point. -----Output----- For each test case, print a single line containing one real number — the expected beauty of the exhibition. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. -----Constraints----- - $1 \le N \le 10^5$ - $0 \le b_i \le 10^9$ for each valid $i$ - $0 \le p_i \le 1$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $4 \cdot 10^5$ -----Example Input----- 2 3 5 6 2 1.0 0.0 0.5 4 2 2 2 2 0.5 0.5 0.5 0.5 -----Example Output----- 6.000000000000000 1.000000000000000 -----Explanation----- Example case 1: The first painting must be displayed at the exhibition, the second one must be excluded. If the third painting is displayed (with probability $0.5$), the beauty is $5 \oplus 2 = 7$; if it is excluded (with probability $0.5$), the beauty is $5$. The expected beauty is $0.5 \cdot 5 + 0.5 \cdot 7 = 6$. Example case 2: If there is an odd number of paintings at the exhibition, the beauty is $2$; this has a probability of $0.5$. If there is an even number of paintings, the beauty is $0$ (with probability $0.5$), so the expected beauty is $0.5 \cdot 0 + 0.5 \cdot 2 = 1$.
t = int(input()) while t: x = 0 n = int(input()) b = list(map(int, input().strip().split())) p = list(map(float, input().strip().split())) for i in range(30): pb = 0.0 for j in range(n): if b[j] & 1 << i: pb = pb * (1 - p[j]) + (1 - pb) * p[j] x += (1 << i) * pb print(x) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
Monisha likes to paint. She has painted $N$ paintings (numbered $1$ through $N$) and wants to choose some subset of these paintings for an exhibition. For each valid $i$, the $i$-th painting has beauty $b_i$ and the probability that it will be displayed at the exhibition is $p_i$. Each painting is chosen or excluded from the exhibition independently randomly. The beauty of the resulting exhibition is the bitwise XOR of the beauties of all displayed paintings. If no paintings are displayed, the XOR is $0$. Monisha wants to find out how beautiful her exhibition is going to be. Help her compute the expected value of the beauty of the exhibition. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $b_1, b_2, \ldots, b_N$. - The third line contains $N$ space-separated real numbers $p_1, p_2, \ldots, p_N$. Each of these numbers is given with at most five digits after the decimal point. -----Output----- For each test case, print a single line containing one real number — the expected beauty of the exhibition. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. -----Constraints----- - $1 \le N \le 10^5$ - $0 \le b_i \le 10^9$ for each valid $i$ - $0 \le p_i \le 1$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $4 \cdot 10^5$ -----Example Input----- 2 3 5 6 2 1.0 0.0 0.5 4 2 2 2 2 0.5 0.5 0.5 0.5 -----Example Output----- 6.000000000000000 1.000000000000000 -----Explanation----- Example case 1: The first painting must be displayed at the exhibition, the second one must be excluded. If the third painting is displayed (with probability $0.5$), the beauty is $5 \oplus 2 = 7$; if it is excluded (with probability $0.5$), the beauty is $5$. The expected beauty is $0.5 \cdot 5 + 0.5 \cdot 7 = 6$. Example case 2: If there is an odd number of paintings at the exhibition, the beauty is $2$; this has a probability of $0.5$. If there is an even number of paintings, the beauty is $0$ (with probability $0.5$), so the expected beauty is $0.5 \cdot 0 + 0.5 \cdot 2 = 1$.
t = int(input()) while t > 0: n = int(input()) B = list(map(int, input().strip().split(" "))) P = list(map(float, input().strip().split(" "))) l = [0] * 32 ans = 0 cur_bit = 1 for i in range(0, 31): cur_prob = 0.0 for j in range(0, len(B)): if cur_bit & B[j]: cur_prob = cur_prob * (1 - P[j]) + (1 - cur_prob) * P[j] cur_bit = cur_bit << 1 ans = ans + cur_prob * 2**i print(ans) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
Monisha likes to paint. She has painted $N$ paintings (numbered $1$ through $N$) and wants to choose some subset of these paintings for an exhibition. For each valid $i$, the $i$-th painting has beauty $b_i$ and the probability that it will be displayed at the exhibition is $p_i$. Each painting is chosen or excluded from the exhibition independently randomly. The beauty of the resulting exhibition is the bitwise XOR of the beauties of all displayed paintings. If no paintings are displayed, the XOR is $0$. Monisha wants to find out how beautiful her exhibition is going to be. Help her compute the expected value of the beauty of the exhibition. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $b_1, b_2, \ldots, b_N$. - The third line contains $N$ space-separated real numbers $p_1, p_2, \ldots, p_N$. Each of these numbers is given with at most five digits after the decimal point. -----Output----- For each test case, print a single line containing one real number — the expected beauty of the exhibition. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. -----Constraints----- - $1 \le N \le 10^5$ - $0 \le b_i \le 10^9$ for each valid $i$ - $0 \le p_i \le 1$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $4 \cdot 10^5$ -----Example Input----- 2 3 5 6 2 1.0 0.0 0.5 4 2 2 2 2 0.5 0.5 0.5 0.5 -----Example Output----- 6.000000000000000 1.000000000000000 -----Explanation----- Example case 1: The first painting must be displayed at the exhibition, the second one must be excluded. If the third painting is displayed (with probability $0.5$), the beauty is $5 \oplus 2 = 7$; if it is excluded (with probability $0.5$), the beauty is $5$. The expected beauty is $0.5 \cdot 5 + 0.5 \cdot 7 = 6$. Example case 2: If there is an odd number of paintings at the exhibition, the beauty is $2$; this has a probability of $0.5$. If there is an even number of paintings, the beauty is $0$ (with probability $0.5$), so the expected beauty is $0.5 \cdot 0 + 0.5 \cdot 2 = 1$.
for _ in range(int(input())): n = int(input()) xl = [int(x) for x in input().split()] pl = [float(x) for x in input().split()] tl = [0] * 30 for x, p in zip(xl, pl): bs = bin(x)[2:][::-1] for i in range(len(bs)): if bs[i] == "1": tl[i] = (1 - tl[i]) * p + (1 - p) * tl[i] ans = 0 for i in range(30): ans += 2**i * tl[i] print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
Monisha likes to paint. She has painted $N$ paintings (numbered $1$ through $N$) and wants to choose some subset of these paintings for an exhibition. For each valid $i$, the $i$-th painting has beauty $b_i$ and the probability that it will be displayed at the exhibition is $p_i$. Each painting is chosen or excluded from the exhibition independently randomly. The beauty of the resulting exhibition is the bitwise XOR of the beauties of all displayed paintings. If no paintings are displayed, the XOR is $0$. Monisha wants to find out how beautiful her exhibition is going to be. Help her compute the expected value of the beauty of the exhibition. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $b_1, b_2, \ldots, b_N$. - The third line contains $N$ space-separated real numbers $p_1, p_2, \ldots, p_N$. Each of these numbers is given with at most five digits after the decimal point. -----Output----- For each test case, print a single line containing one real number — the expected beauty of the exhibition. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. -----Constraints----- - $1 \le N \le 10^5$ - $0 \le b_i \le 10^9$ for each valid $i$ - $0 \le p_i \le 1$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $4 \cdot 10^5$ -----Example Input----- 2 3 5 6 2 1.0 0.0 0.5 4 2 2 2 2 0.5 0.5 0.5 0.5 -----Example Output----- 6.000000000000000 1.000000000000000 -----Explanation----- Example case 1: The first painting must be displayed at the exhibition, the second one must be excluded. If the third painting is displayed (with probability $0.5$), the beauty is $5 \oplus 2 = 7$; if it is excluded (with probability $0.5$), the beauty is $5$. The expected beauty is $0.5 \cdot 5 + 0.5 \cdot 7 = 6$. Example case 2: If there is an odd number of paintings at the exhibition, the beauty is $2$; this has a probability of $0.5$. If there is an even number of paintings, the beauty is $0$ (with probability $0.5$), so the expected beauty is $0.5 \cdot 0 + 0.5 \cdot 2 = 1$.
def findout(P): ans = 1 ans2 = 1 for x in P: ans *= 2 * x - 1 if len(P) % 2 == 0: return (1 - ans) / 2 else: return (1 + ans) / 2 def find(b, p): B = max(b) okay = len(bin(B)[2:]) new_b = [] for x in b: new_b += [("0" * (okay - len(bin(x)[2:])) + bin(x)[2:])[::-1]] ans = 0 for i in range(okay): temp_s = "" ones = [] for j in range(len(new_b)): if new_b[j][i] == "1": ones += [p[j]] want = findout(ones) ans += 2**i * want return ans T = int(input()) for _ in range(T): N = int(input()) b = list(map(int, input().strip().split(" "))) p = list(map(float, input().strip().split(" "))) print(find(b, p))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN BIN_OP BIN_OP NUMBER VAR NUMBER RETURN BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR LIST BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Monisha likes to paint. She has painted $N$ paintings (numbered $1$ through $N$) and wants to choose some subset of these paintings for an exhibition. For each valid $i$, the $i$-th painting has beauty $b_i$ and the probability that it will be displayed at the exhibition is $p_i$. Each painting is chosen or excluded from the exhibition independently randomly. The beauty of the resulting exhibition is the bitwise XOR of the beauties of all displayed paintings. If no paintings are displayed, the XOR is $0$. Monisha wants to find out how beautiful her exhibition is going to be. Help her compute the expected value of the beauty of the exhibition. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $b_1, b_2, \ldots, b_N$. - The third line contains $N$ space-separated real numbers $p_1, p_2, \ldots, p_N$. Each of these numbers is given with at most five digits after the decimal point. -----Output----- For each test case, print a single line containing one real number — the expected beauty of the exhibition. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. -----Constraints----- - $1 \le N \le 10^5$ - $0 \le b_i \le 10^9$ for each valid $i$ - $0 \le p_i \le 1$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $4 \cdot 10^5$ -----Example Input----- 2 3 5 6 2 1.0 0.0 0.5 4 2 2 2 2 0.5 0.5 0.5 0.5 -----Example Output----- 6.000000000000000 1.000000000000000 -----Explanation----- Example case 1: The first painting must be displayed at the exhibition, the second one must be excluded. If the third painting is displayed (with probability $0.5$), the beauty is $5 \oplus 2 = 7$; if it is excluded (with probability $0.5$), the beauty is $5$. The expected beauty is $0.5 \cdot 5 + 0.5 \cdot 7 = 6$. Example case 2: If there is an odd number of paintings at the exhibition, the beauty is $2$; this has a probability of $0.5$. If there is an even number of paintings, the beauty is $0$ (with probability $0.5$), so the expected beauty is $0.5 \cdot 0 + 0.5 \cdot 2 = 1$.
for _ in range(int(input())): n = int(input()) beauty, prob = list(map(int, input().split())), list(map(float, input().split())) exp0, exp1 = [(1.0) for _ in range(31)], [(0.0) for _ in range(31)] for i in range(n): curr_beauty, curr_prob, j = beauty[i], prob[i], 0 while 30 >= j and 0 != curr_beauty: if curr_beauty & 1: exp0[j] = exp1[j] * curr_prob + exp0[j] * (1 - curr_prob) exp1[j] = 1 - exp0[j] curr_beauty, j = curr_beauty // 2, j + 1 ans, j, mul = 0.0, 0, 1 while 30 >= j: ans, mul, j = ans + mul * exp1[j], mul * 2, j + 1 print("%.9f" % ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER WHILE NUMBER VAR NUMBER VAR IF BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR
Monisha likes to paint. She has painted $N$ paintings (numbered $1$ through $N$) and wants to choose some subset of these paintings for an exhibition. For each valid $i$, the $i$-th painting has beauty $b_i$ and the probability that it will be displayed at the exhibition is $p_i$. Each painting is chosen or excluded from the exhibition independently randomly. The beauty of the resulting exhibition is the bitwise XOR of the beauties of all displayed paintings. If no paintings are displayed, the XOR is $0$. Monisha wants to find out how beautiful her exhibition is going to be. Help her compute the expected value of the beauty of the exhibition. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $b_1, b_2, \ldots, b_N$. - The third line contains $N$ space-separated real numbers $p_1, p_2, \ldots, p_N$. Each of these numbers is given with at most five digits after the decimal point. -----Output----- For each test case, print a single line containing one real number — the expected beauty of the exhibition. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. -----Constraints----- - $1 \le N \le 10^5$ - $0 \le b_i \le 10^9$ for each valid $i$ - $0 \le p_i \le 1$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $4 \cdot 10^5$ -----Example Input----- 2 3 5 6 2 1.0 0.0 0.5 4 2 2 2 2 0.5 0.5 0.5 0.5 -----Example Output----- 6.000000000000000 1.000000000000000 -----Explanation----- Example case 1: The first painting must be displayed at the exhibition, the second one must be excluded. If the third painting is displayed (with probability $0.5$), the beauty is $5 \oplus 2 = 7$; if it is excluded (with probability $0.5$), the beauty is $5$. The expected beauty is $0.5 \cdot 5 + 0.5 \cdot 7 = 6$. Example case 2: If there is an odd number of paintings at the exhibition, the beauty is $2$; this has a probability of $0.5$. If there is an even number of paintings, the beauty is $0$ (with probability $0.5$), so the expected beauty is $0.5 \cdot 0 + 0.5 \cdot 2 = 1$.
t = int(input()) for _ in range(t): n = int(input()) b = [int(i) for i in input().split()] p = [float(i) for i in input().split()] pb = [0] * 30 for i in range(n): h = b[i] j = 0 while h: if h % 2 == 1: x = pb[j] y = p[i] pb[j] = x * (1 - y) + y * (1 - x) h = h // 2 j += 1 ans = 0 k = 1 for i in pb: ans += k * i k *= 2 print("%.10f" % 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR
Monisha likes to paint. She has painted $N$ paintings (numbered $1$ through $N$) and wants to choose some subset of these paintings for an exhibition. For each valid $i$, the $i$-th painting has beauty $b_i$ and the probability that it will be displayed at the exhibition is $p_i$. Each painting is chosen or excluded from the exhibition independently randomly. The beauty of the resulting exhibition is the bitwise XOR of the beauties of all displayed paintings. If no paintings are displayed, the XOR is $0$. Monisha wants to find out how beautiful her exhibition is going to be. Help her compute the expected value of the beauty of the exhibition. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $b_1, b_2, \ldots, b_N$. - The third line contains $N$ space-separated real numbers $p_1, p_2, \ldots, p_N$. Each of these numbers is given with at most five digits after the decimal point. -----Output----- For each test case, print a single line containing one real number — the expected beauty of the exhibition. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. -----Constraints----- - $1 \le N \le 10^5$ - $0 \le b_i \le 10^9$ for each valid $i$ - $0 \le p_i \le 1$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $4 \cdot 10^5$ -----Example Input----- 2 3 5 6 2 1.0 0.0 0.5 4 2 2 2 2 0.5 0.5 0.5 0.5 -----Example Output----- 6.000000000000000 1.000000000000000 -----Explanation----- Example case 1: The first painting must be displayed at the exhibition, the second one must be excluded. If the third painting is displayed (with probability $0.5$), the beauty is $5 \oplus 2 = 7$; if it is excluded (with probability $0.5$), the beauty is $5$. The expected beauty is $0.5 \cdot 5 + 0.5 \cdot 7 = 6$. Example case 2: If there is an odd number of paintings at the exhibition, the beauty is $2$; this has a probability of $0.5$. If there is an even number of paintings, the beauty is $0$ (with probability $0.5$), so the expected beauty is $0.5 \cdot 0 + 0.5 \cdot 2 = 1$.
T = int(input()) for i in range(0, T): N = int(input()) b = [int(x) for x in input().split()] p = [float(x) for x in input().split()] arr = [0] * 32 for j in range(0, len(b)): st = bin(b[j]) st = st[2:] for k in range(1, len(st) + 1): if st[-k] == "1": arr[k - 1] = (1 - arr[k - 1]) * p[j] + (1 - p[j]) * arr[k - 1] exp = 0 xr = 1 for j in range(0, len(arr)): exp = exp + xr * arr[j] xr = xr * 2 print(exp)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Monisha likes to paint. She has painted $N$ paintings (numbered $1$ through $N$) and wants to choose some subset of these paintings for an exhibition. For each valid $i$, the $i$-th painting has beauty $b_i$ and the probability that it will be displayed at the exhibition is $p_i$. Each painting is chosen or excluded from the exhibition independently randomly. The beauty of the resulting exhibition is the bitwise XOR of the beauties of all displayed paintings. If no paintings are displayed, the XOR is $0$. Monisha wants to find out how beautiful her exhibition is going to be. Help her compute the expected value of the beauty of the exhibition. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $b_1, b_2, \ldots, b_N$. - The third line contains $N$ space-separated real numbers $p_1, p_2, \ldots, p_N$. Each of these numbers is given with at most five digits after the decimal point. -----Output----- For each test case, print a single line containing one real number — the expected beauty of the exhibition. Your answer will be considered correct if its absolute or relative error does not exceed $10^{-6}$. -----Constraints----- - $1 \le N \le 10^5$ - $0 \le b_i \le 10^9$ for each valid $i$ - $0 \le p_i \le 1$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $4 \cdot 10^5$ -----Example Input----- 2 3 5 6 2 1.0 0.0 0.5 4 2 2 2 2 0.5 0.5 0.5 0.5 -----Example Output----- 6.000000000000000 1.000000000000000 -----Explanation----- Example case 1: The first painting must be displayed at the exhibition, the second one must be excluded. If the third painting is displayed (with probability $0.5$), the beauty is $5 \oplus 2 = 7$; if it is excluded (with probability $0.5$), the beauty is $5$. The expected beauty is $0.5 \cdot 5 + 0.5 \cdot 7 = 6$. Example case 2: If there is an odd number of paintings at the exhibition, the beauty is $2$; this has a probability of $0.5$. If there is an even number of paintings, the beauty is $0$ (with probability $0.5$), so the expected beauty is $0.5 \cdot 0 + 0.5 \cdot 2 = 1$.
t = int(input()) while t > 0: n = int(input()) b = [int(x) for x in input().split()] p = [float(x) for x in input().split()] s = [0] * 10 yet = 2 mx = 0 for i in range(n): st = bin(b[i]) rng = len(st) - 2 if rng + 2 > yet: for ml in range(rng + 2 - yet): s.append(0) if rng > mx: mx = rng for k in range(2, rng + 2): if st[k] == "1": s[rng - k + 1] = ( s[rng - k + 1] * (1 - p[i]) + (1 - s[rng - k + 1]) * p[i] ) mult = 1 ans = 0 for i in range(0, mx): ans += mult * s[i] mult = mult * 2 print("%.16f" % ans) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR NUMBER
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
from sys import stderr def count_barfuls_by_ending(d, *, m): n_total = 0 pow2 = 1 while d >= pow2: n_total += (n_total + 1) * pow2 n_total %= m d -= pow2 pow2 <<= 1 n_total += (n_total + 1) * d return n_total % m for _ in range(int(input())): d, m = map(int, input().split(" ")) print(count_barfuls_by_ending(d, m=m))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN BIN_OP 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 STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
import sys def main(): import sys input = sys.stdin.readline for _ in range(int(input())): d, mod = list(map(int, input().split())) LV = d.bit_length() ans = 0 for lv in range(1, LV): new = (ans + 1) * (1 << lv - 1) % mod ans += new ans %= mod n = d - (1 << LV - 1) + 1 new = (ans + 1) * n % mod ans += new ans %= mod print(ans) def __starting_point(): main() __starting_point()
IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
for q in range(int(input())): dp = [0] * 35 d, m = [int(i) for i in input().split()] for i in range(1, 35): dp[i] = (pow(2, i - 1, m) * (dp[i - 1] + 1) + dp[i - 1]) % m bn = bin(d) k = len(bn) - 3 mm = d - (1 << k) ans = (dp[k] * (mm + 2) + mm + 1) % m print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
aas = [] for _ in range(int(input())): d, m = map(int, input().split()) A = [] s = 1 sus = 0 while sus + s <= d: A.append(s) sus += s s *= 2 A.append(d - sum(A)) ans = 1 for x in A: ans *= x + 1 ans %= m ans -= 1 ans %= m aas.append(str(ans)) print("\n".join(aas))
ASSIGN VAR LIST 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 LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
import sys input = sys.stdin.readline T = int(input()) for _ in range(T): D, M = map(int, input().split()) L = [] rem = D for i in range(40): n = 1 << i n = min(n, rem) L.append(n) rem -= n if rem == 0: break ans = 1 for l in L: ans = ans * (l + 1) % M print((ans - 1) % M)
IMPORT ASSIGN VAR 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 LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input()) for _ in range(t): d, m = map(int, input().split()) pot = [1] * 1000 for i in range(1, 1000): pot[i] = 2 * pot[i - 1] % m makscyfr = 0 dd = d while dd > 0: makscyfr += 1 dd //= 2 dp = [0] * (makscyfr + 1) dp[1] = 1 for i in range(2, makscyfr + 1): s = 1 for j in range(1, i): s += dp[j] s *= pot[i - 1] s %= m dp[i] = s ii = 0 while 2 ** (ii + 1) <= d: ii += 1 odp = 0 for kk in range(1, makscyfr): odp += dp[kk] mno = d + 1 - 2**ii for j in range(1, ii + 1): odp += mno * dp[j] odp += mno odp %= m print(odp)
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 FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input()) for loop in range(t): d, mod = map(int, input().split()) sb = format(d, "b") ans = 0 pr = 0 for i in range(len(sb)): if i != len(sb) - 1: ans += (ans + 1) * 2**i else: ans += (ans + 1) * (d - 2**i + 1) ans %= mod print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
import sys lines = sys.stdin.readlines() T = int(lines[0].strip()) def solve(d, m): s = bin(d)[2:] res = 1 for i in range(len(s) - 1): res = (1 + 2**i) * res % m res = res * (d - 2 ** (len(s) - 1) + 2) % m res = (res - 1 + m) % m print(res) for t in range(1, T + 1): d, m = map(int, lines[t].strip().split(" ")) solve(d, m)
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input()) for f in range(t): d, m = map(int, input().split()) n = 1 p = 1 while d >= 2 * p: n += 1 p *= 2 s = [0] * n s[0] = 1 for i in range(n - 1): pos = min(2 ** (i + 1), d + 1 - 2 ** (i + 1)) s[i + 1] = pos for j in range(i + 1): s[i + 1] += pos * s[j] s[i + 1] %= m sol = 0 for i in range(n): sol += s[i] sol %= m print(sol)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
a = [1] for i in range(30): a.append(a[-1] * 2) for t in range(int(input())): d, m = map(int, input().split()) ans = 1 z = d.bit_length() for i in range(z): if i != z - 1: ans = ans * (a[i + 1] - 1 - a[i] + 2) % m else: ans = ans * (d - a[i] + 2) % m print((ans - 1) % m)
ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
q = int(input()) for i in range(q): inp = input().split() p = int(inp[0]) n = int(inp[1]) e = 1 a = 1 t = 0 while e * 2 <= p: t += e * a e *= 2 a = t + 1 t %= n t += (p - e + 1) * a t %= n print(t)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): d, m = [int(a) for a in input().split()] start = 1 end = 2 total = 1 while start <= d: total *= min(end, d + 1) - start + 1 total %= m start *= 2 end *= 2 print((total + m - 1) % m)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
import sys def input(): return sys.stdin.readline().rstrip() INF = 1 << 64 def filter(ord, M): if 1 << ord <= M: return min(M - (1 << ord) + 1, 1 << ord) else: return 0 def slv(): d, mod = map(int, input().split()) K = d.bit_length() - 1 DP = [([0] * (K + 1)) for i in range(K + 1)] for i in range(K + 1): DP[0][i] = filter(i, d) for i in range(1, K + 1): for bit in range(K + 1): if bit == 0: if i == 0: DP[i][bit] = 1 else: for last_bit in range(bit): DP[i][bit] += DP[i - 1][last_bit] * filter(bit, d) DP[i][bit] %= mod ans = sum(DP[i][j] for i in range(K + 1) for j in range(K + 1)) ans %= mod print(ans) return def main(): t = int(input()) for i in range(t): slv() return main()
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF IF BIN_OP NUMBER VAR VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER VAR RETURN NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN EXPR FUNC_CALL VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
def main(): t = int(input()) power = [1] for i in range(1, 31): power.append(power[i - 1] * 2) for _ in range(t): d, m = map(int, input().split()) k = 0 p = d while p != 0: k += 1 p //= 2 basen = power[k - 1] pp = [d - basen + 2] for i in range(1, k): pp.append(power[i - 1] + 1) p = 1 for i in pp: p *= i p -= 1 print(p % m) return main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN EXPR FUNC_CALL VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
import sys input = sys.stdin.readline t = int(input()) D = [((1 << i) - 1) for i in range(1, 32)] for tests in range(t): d, m = map(int, input().split()) ANS = [1] B = [0] for i in range(1, 32): B.append(ANS[-1] + 1) ANS.append((ANS[-1] + B[-1] * (1 << i)) % m) for i in range(32): if d < D[i]: break A = ANS[i - 1] A = (A + (d - D[i - 1]) * B[i]) % m print(A)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
T = int(input()) for case in range(T): d, m = [int(x) for x in input().split()] i = 0 tot = 1 while 2**i <= d: r = 2**i, min(d + 1, 2 ** (i + 1)) nr = r[1] - r[0] tot *= nr + 1 tot = tot % m i += 1 tot = (tot - 1) % m print(tot)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
def go(): d, m = map(int, input().split()) i = d.bit_length() res = 0 while i >= 0: bi = 1 << i if d >= bi: res += bitvals[i] % m * (d - bi + 1) res = res % m d = bi - 1 i -= 1 return res % m bitvals = [1] for i in range(33): bitvals.append(bitvals[-1] * (2**i + 1)) t = int(input()) ans = [] for _ in range(t): ans.append(str(go())) print("\n".join(ans))
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input()) for _ in range(t): d, m = map(int, input().split()) ans = 1 i = 0 r = min(2 ** (i + 1) - 1, d) - 2**i + 2 while r > 0: ans *= r i += 1 r = min(2 ** (i + 1) - 1, d) - 2**i + 2 print((ans - 1) % 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
import sys k = int(input()) t = -1 def input(): global t t += 1 return data[t] data = sys.stdin.readlines() for _ in range(k): d, m = map(int, input().split()) x = 1 p = 0 s = 1 while 2 * x <= d: s *= x + 1 s %= m p += 1 x *= 2 answer = (d - x + 2) % m print((answer * s - 1) % m)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input()) for _ in range(t): d, m = list(map(int, input().split())) d += 1 out = 1 curr = 2 while curr < d: out *= curr // 2 + 1 out %= m curr *= 2 out *= d - curr // 2 + 1 print((out - 1) % m)
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 VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): d, m = map(int, input().split()) ans = 1 i = 0 while pow(2, i) <= d: ans = ans % m * (1 + min(pow(2, i + 1) - pow(2, i), d - pow(2, i) + 1) % m) % m i += 1 print((ans - 1 + m) % m)
IMPORT ASSIGN VAR 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 NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input()) for _ in range(t): d, m = map(int, input().split()) a = [] i = 0 while d > (1 << i + 1) - 1: a.append(1 << i) i += 1 a.append((1 << i) - (1 << i + 1) + d + 1) ans = 1 for x in a: ans *= x + 1 ans %= m print((ans - 1) % 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 LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
for _ in range(int(input())): d, m = map(int, input().split()) ans = 1 for i in range(1, 31): l = max(1, 1 << i - 1) r = min(d, (1 << i) - 1) ans = ans * (1 + (r - l + 1)) % m if r == d: break print((ans - 1 + m) % m)
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 NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input()) for _ in range(t): d, m = map(int, input().split()) mm = -1 for i in range(0, 34): if 1 << i & d != 0: mm = i count, temp = 1, 1 for i in range(mm + 1): if 1 << i + 1 > d: temp = d - (1 << i) + 2 else: temp = (1 << i) + 1 temp = temp % m count = count * temp % m print((count - 1 + m) % 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
import itertools import sys input = sys.stdin.readline cnt = 0 log_size = (10**11).bit_length() dp = [0] * log_size dp[0] = 1 sum_ = 2 for i in range(log_size - 1): dp[i + 1] = sum_ sum_ += 2 ** (i + 1) * dp[i + 1] t = int(input()) for _ in range(t): d, MOD = map(int, input().split()) ans = 0 for i in range(log_size): if 2**i <= d: dpp = dp[i] % MOD ans += dpp * min(d - 2**i + 1, 2**i) ans %= MOD print(ans)
IMPORT IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
T = int(input()) for _ in range(T): D, M = map(int, input().split(" ")) x = D pow2 = [1] while x: pow2.append(pow2[-1] * 2 % M) x //= 2 ans = 1 for x in pow2[:-2]: ans = ans * (x + 1) % M ans = (ans * (D - pow2[-2] + 2 + M) % M - 1 + M) % M print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR LIST NUMBER WHILE VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
from itertools import accumulate t = int(input()) for _ in range(t): d, m = map(int, input().split()) per_bit = [] x = 1 while x * 2 <= d: per_bit.append(x) x *= 2 per_bit.append(d - sum(per_bit)) cur = per_bit[:] total = 0 while sum(cur): acc = list(accumulate(cur)) total += acc[-1] total %= m new = [0] for i in range(1, len(cur)): new.append(acc[i - 1] * per_bit[i] % m) cur = new print(total)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
arr = [ [1, 1, 1], [2, 3, 2], [4, 11, 6], [8, 59, 30], [16, 539, 270], [32, 9179, 4590], [64, 302939, 151470], [128, 19691099, 9845550], [256, 2540151899, 1270075950], [512, 652819038299, 326409519150], [1024, 334896166647899, 167448083323950], [2048, 343268570814097499, 171634285407048750], [4096, 703357301598085777499, 351678650799042888750], [8192, 2881654864647357430417499, 1440827432323678715208750], [16384, 23609398306055799427410577499, 11804699153027899713705288750], [32768, 386839991244724273618122312337499, 193419995622362136809061156168750], [ 65536, 12676359673098369722192250052987537499, 6338179836549184861096125026493768750, ], [ 131072, 830770583895847856483313491722644245137499, 415385291947923928241656745861322122568750, ], [ 262144, 108891592742980466092837349300562149142907537499, 54445796371490233046418674650281074571453768750, ], [ 524288, 28545386579608614283906846932395864587067496417937499, 14272693289804307141953423466197932293533748208968750, ], [ 1048576, 14966032184436420774295236871338895448489030629464033937499, 7483016092218210387147618435669447724244515314732016968750, ], [ 2097152, 15693037129859788786248176592837924972690282270351508314081937499, 7846518564929894393124088296418962486345141135175754157040968750, ], [ 4194304, 32910699895996845632446722286199832870252343534114476715401877473937499, 16455349947998422816223361143099916435126171767057238357700938736968750, ], [ 8388608, 138037513127279049620399449518619390006863755746854020259793671698323425937499, 69018756563639524810199724759309695003431877873427010129896835849161712968750, ], [ 16777216, 1157942724957111181157129405826936282586087363231861356037487532551601175730145937499, 578971362478555590578564702913468141293043681615930678018743766275800587865072968750, ], [ 33554432, 19427056370176769979399471138639574458120108873898759284155188468412776622679791835105937499, 9713528185088384989699735569319787229060054436949379642077594234206388311339895917552968750, ], [ 67108864, 651863861360319626430170934556915312303502499161941367183313233065729129529675355585009227745937499, 325931930680159813215085467278457656151751249580970683591656616532864564764837677792504613872968750, ], [ 134217728, 43745843870408406166952773174103864509808588243421336348220398010521552280174496931781380288556373985937499, 21872921935204203083476386587051932254904294121710668174110199005260776140087248465890690144278186992968750, ], [ 268435456, 5871467817474786578237996065680342304630206938728110954803295012448320852599792701901164786815401204867209185937499, 2935733908737393289118998032840171152315103469364055477401647506224160426299896350950582393407700602433604592968750, ], [ 536870912, 1576110146844636921106782728655104702459842815602051462899328841772385696950254992040103938381099797066879922141730785937499, 788055073422318460553391364327552351229921407801025731449664420886192848475127496020051969190549898533439961070865392968750, ], ] t = int(input()) for _ in range(t): [d, m] = [int(x) for x in input().split()] for p in arr: if d >= p[0] and d < p[0] * 2: print((p[1] + p[2] * (d - p[0])) % m)
ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
for _ in range(int(input())): [n, m] = list(map(int, input().split())) k = 1 arr = [] while n >= k: n -= k arr.append(k) k *= 2 if n: arr.append(n) ans = 1 for i in arr: ans *= i + 1 print((ans - 1) % m)
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 NUMBER ASSIGN VAR LIST WHILE VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input()) def solve(d, m): ans = 1 for i in range(30): if d < 1 << i: break ans = ans * (min((1 << i + 1) - 1, d) - (1 << i) + 2) % m ans -= 1 if ans < 0: ans += m return ans while t: t -= 1 d, m = [int(c) for c in input().split()] print(solve(d, m))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR VAR RETURN VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
for q in range(int(input())): n, m = map(int, input().split()) st, ans = 1, 1 while st <= n: ans *= min(st * 2 - st + 1, n - st + 2) st *= 2 print((ans - 1) % m)
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 NUMBER NUMBER WHILE VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
for i in range(int(input())): d, m = map(int, input().split()) a, k, s = [], 1, 1 while s < d: a.append(k) k <<= 1 s += k a.append(d - s + k) dp = [1] for j in range(len(a)): dp.append((a[j] + 1) * dp[-1]) print((dp[-1] - 1) % m)
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 LIST NUMBER NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
for t in range(int(input())): d, m = [int(i) for i in input().split()] tot = 0 p = 1 while p <= d: p *= 2 p //= 2 while d > 0: tot += (d - p + 1) * (tot + 1) tot %= m d = p - 1 p //= 2 print(tot)
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 NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
t = int(input().strip()) for k in range(t): d, m = map(int, input().strip().split()) o = 1 oo = d c = 0 while oo > 0: c += 1 oo = oo // 2 while o <= d: o = o * 2 o = o // 2 ll = [(0) for i in range(c + 1)] start = o fin = d s = fin - start + 1 ll[c] = s for e in range(c - 1, 0, -1): fin = start - 1 start = start // 2 ll[e] = (fin - start + 1 + (fin - start + 1) * ll[e + 1] + ll[e + 1]) % m print(ll[1] % m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
store = [] maxes = [0] def s(nums, M): p = 1 for num in nums: p = p * ((1 + num) % M) % M if p == 0: return M - 1 return (p - 1) % M i = 0 while 2**i <= 10**9: store.append(2**i) maxes.append(2 ** (i + 1) - 1) i += 1 T = int(input()) for t in range(T): d, m = [int(i) for i in input().split()] ans = [] for i in range(1, len(maxes)): if maxes[i] <= d: ans.append(maxes[i] - maxes[i - 1]) else: if d != maxes[i - 1]: ans.append(d - maxes[i - 1]) break final = s(ans, m) print(final)
ASSIGN VAR LIST ASSIGN VAR LIST NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR VAR VAR IF VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
T = int(input()) for t in range(T): d, m = map(int, input().split()) bd = bin(d)[2:] lbd = len(bd) ans = d - (1 << lbd - 1) + 1 for b in range(len(bd) - 1, 0, -1): q = 1 << b - 1 ans = (ans + ans * q + q) % m print(ans % 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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
import sys def main(): t = int(input()) allans = [] for _ in range(t): d, m = readIntArr() dMSB = 0 d2 = d while d2 > 0: dMSB += 1 d2 = d2 >> 1 nWaysAtThisMSB = [(0) for _ in range(dMSB + 1)] for msb in range(1, dMSB): nWaysAtThisMSB[msb] = pow(2, msb - 1, m) nWaysAtThisMSB[dMSB] = (d - (2 ** (dMSB - 1) - 1)) % m dp = [(0) for _ in range(dMSB + 1)] for i in range(1, dMSB + 1): dp[i] += dp[i - 1] dp[i] %= m dp[i] += nWaysAtThisMSB[i] dp[i] %= m dp[i] += dp[i - 1] * nWaysAtThisMSB[i] dp[i] %= m allans.append(dp[dMSB]) multiLineArrayPrint(allans) return input = lambda: sys.stdin.readline().rstrip("\r\n") def oneLineArrayPrint(arr): print(" ".join([str(x) for x in arr])) def multiLineArrayPrint(arr): print("\n".join([str(x) for x in arr])) def multiLineArrayOfArraysPrint(arr): print("\n".join([" ".join([str(x) for x in y]) for y in arr])) def readIntArr(): return [int(x) for x in input().split()] inf = float("inf") MOD = 10**9 + 7 main()
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
def calc(n): a = n.bit_length() - 1 X = [0] * 30 X[a] = n - (1 << a) + 1 for i in range(a): X[i] = 1 << i return X T = int(input()) for _ in range(T): d, m = map(int, input().split()) s = 1 for a in calc(d): s = s * (a + 1) % m print((s - 1) % m)
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER 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 NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \ge 1$ $1 \le a_1 < a_2 < \dots < a_n \le d$ Define an array $b$ of length $n$ as follows: $b_1 = a_1$, $\forall i > 1, b_i = b_{i - 1} \oplus a_i$, where $\oplus$ is the bitwise exclusive-or (xor). After constructing an array $b$, the constraint $b_1 < b_2 < \dots < b_{n - 1} < b_n$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $m$. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 100$) denoting the number of test cases in the input. Each of the next $t$ lines contains two integers $d, m$ ($1 \leq d, m \leq 10^9$). Note that $m$ is not necessary the prime! -----Output----- For each test case, print the number of arrays $a$, satisfying all given constrains, modulo $m$. -----Example----- Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
pre = [1] s = 1 for i in range(1, 31): pre.append(s + 2**i * (s + 1)) s = pre[-1] for nt in range(int(input())): d, m = map(int, input().split()) if d == 1: print(1 % m) continue if d == 2: print(3 % m) continue arr = [] s = 0 ans = 0 for i in range(30): if s + 2**i <= d: ans = max(ans, pre[i]) s += 2**i else: rem = d - s break ans += (ans + 1) * rem print(ans % m)
ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Alice recently converted all the positive integers from 1 to 2^{N} - 1 (both inclusive) into binary strings and stored them in an array S. Note that the binary strings do not have leading zeroes. While she was out, Bob sorted all the elements of S in lexicographical increasing order. Let S_{i} denotes the i^{th} string in the sorted array. Alice defined a function F such that F(S_{i}) is equal to the count of 1 in the string S_{i}. For example, F(101) = 2 and F(1000) = 1. Given a positive integer K, find the value of \sum_{i = 1}^K F(S_{i}). String P is lexicographically smaller than string Q if one of the following satisfies: P is a prefix of Q and P \neq Q. There exists an index i such that P_{i} < Q_{i} and for all j < i, P_{j}=Q_{j}. ------ Input Format ------ - The first line will contain an integer T - number of test cases. Then the test cases follow. - The first and only line of each test case contains two integers N and K. ------ Output Format ------ For each test case, output the value \sum_{i = 1}^K F(S_{i}). ------ Constraints ------ $1 ≤ T ≤ 3000$ $1 ≤ N ≤ 50$ $1 ≤ K ≤ 2^{N} - 1$ - Sum of $N$ over all test cases does not exceed $10^{5}$. ----- Sample Input 1 ------ 3 3 2 3 4 3 7 ----- Sample Output 1 ------ 2 5 12 ----- explanation 1 ------ Converting positive integers to Binary Strings: - $1 = 1$ - $2 = 10$ - $3 = 11$ - $4 = 100$ - $5 = 101$ - $6 = 110$ - $7 = 111$ Sorting Binary Strings in lexicographical order: After sorting, the strings will appear in the following order: $[1, 10, 100, 101, 11, 110, 111]$. Test case $1$: $F(S_{1}) + F(S_{2}) = F(1) + F(10) = 1 + 1 = 2$. Test case $2$: $F(S_{1}) + F(S_{2}) + F(S_{3}) + F(S_{4}) = F(1) + F(10) + F(100) + F(101) = 1 + 1 + 1 + 2 = 5$.
def value(N, k): if k == 1: return 1 elif k <= 2 ** (N - 1): return value(N - 1, k - 1) else: return value(N - 1, k - 2 ** (N - 1)) + 1 def sumk(N, k): if k == 1: return 1 elif k <= 2 ** (N - 1): return 1 + sumk(N - 1, k - 1) else: return ( 1 + (N - 1) * 2 ** (N - 2) + (k - 2 ** (N - 1)) + sumk(N - 1, k - 2 ** (N - 1)) ) T = int(input()) for i in range(T): N, K = map(int, input().split(" ")) print(sumk(N, K))
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Alice recently converted all the positive integers from 1 to 2^{N} - 1 (both inclusive) into binary strings and stored them in an array S. Note that the binary strings do not have leading zeroes. While she was out, Bob sorted all the elements of S in lexicographical increasing order. Let S_{i} denotes the i^{th} string in the sorted array. Alice defined a function F such that F(S_{i}) is equal to the count of 1 in the string S_{i}. For example, F(101) = 2 and F(1000) = 1. Given a positive integer K, find the value of \sum_{i = 1}^K F(S_{i}). String P is lexicographically smaller than string Q if one of the following satisfies: P is a prefix of Q and P \neq Q. There exists an index i such that P_{i} < Q_{i} and for all j < i, P_{j}=Q_{j}. ------ Input Format ------ - The first line will contain an integer T - number of test cases. Then the test cases follow. - The first and only line of each test case contains two integers N and K. ------ Output Format ------ For each test case, output the value \sum_{i = 1}^K F(S_{i}). ------ Constraints ------ $1 ≤ T ≤ 3000$ $1 ≤ N ≤ 50$ $1 ≤ K ≤ 2^{N} - 1$ - Sum of $N$ over all test cases does not exceed $10^{5}$. ----- Sample Input 1 ------ 3 3 2 3 4 3 7 ----- Sample Output 1 ------ 2 5 12 ----- explanation 1 ------ Converting positive integers to Binary Strings: - $1 = 1$ - $2 = 10$ - $3 = 11$ - $4 = 100$ - $5 = 101$ - $6 = 110$ - $7 = 111$ Sorting Binary Strings in lexicographical order: After sorting, the strings will appear in the following order: $[1, 10, 100, 101, 11, 110, 111]$. Test case $1$: $F(S_{1}) + F(S_{2}) = F(1) + F(10) = 1 + 1 = 2$. Test case $2$: $F(S_{1}) + F(S_{2}) + F(S_{3}) + F(S_{4}) = F(1) + F(10) + F(100) + F(101) = 1 + 1 + 1 + 2 = 5$.
def func(n, k, toggle): if k == 2**n - 1: return n * 2 ** (n - 1) - (toggle ^ 1) * k * 1 if n == 1: return toggle if k <= 2**n // 2: return toggle * k * 1 + func(n - 1, k - 1, 0) else: return ( toggle * k * 1 + func(n - 1, 2 ** (n - 1) - 1, 0) + func(n - 1, k - 2**n // 2, 1) ) for case in range(int(input())): N, K = map(int, input().split()) print(func(N, K, 1))
FUNC_DEF IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN VAR IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER
Alice recently converted all the positive integers from 1 to 2^{N} - 1 (both inclusive) into binary strings and stored them in an array S. Note that the binary strings do not have leading zeroes. While she was out, Bob sorted all the elements of S in lexicographical increasing order. Let S_{i} denotes the i^{th} string in the sorted array. Alice defined a function F such that F(S_{i}) is equal to the count of 1 in the string S_{i}. For example, F(101) = 2 and F(1000) = 1. Given a positive integer K, find the value of \sum_{i = 1}^K F(S_{i}). String P is lexicographically smaller than string Q if one of the following satisfies: P is a prefix of Q and P \neq Q. There exists an index i such that P_{i} < Q_{i} and for all j < i, P_{j}=Q_{j}. ------ Input Format ------ - The first line will contain an integer T - number of test cases. Then the test cases follow. - The first and only line of each test case contains two integers N and K. ------ Output Format ------ For each test case, output the value \sum_{i = 1}^K F(S_{i}). ------ Constraints ------ $1 ≤ T ≤ 3000$ $1 ≤ N ≤ 50$ $1 ≤ K ≤ 2^{N} - 1$ - Sum of $N$ over all test cases does not exceed $10^{5}$. ----- Sample Input 1 ------ 3 3 2 3 4 3 7 ----- Sample Output 1 ------ 2 5 12 ----- explanation 1 ------ Converting positive integers to Binary Strings: - $1 = 1$ - $2 = 10$ - $3 = 11$ - $4 = 100$ - $5 = 101$ - $6 = 110$ - $7 = 111$ Sorting Binary Strings in lexicographical order: After sorting, the strings will appear in the following order: $[1, 10, 100, 101, 11, 110, 111]$. Test case $1$: $F(S_{1}) + F(S_{2}) = F(1) + F(10) = 1 + 1 = 2$. Test case $2$: $F(S_{1}) + F(S_{2}) + F(S_{3}) + F(S_{4}) = F(1) + F(10) + F(100) + F(101) = 1 + 1 + 1 + 2 = 5$.
T = int(input()) for line in range(T): N, K = map(int, input().split()) digits = [1] prior = [K - 1] counter = K block = 2**N - 1 for d in range(1, N): if counter == 1: break counter -= 1 block = (block + 1) // 2 - 1 if counter <= block: digits.append(0) prior.append(0) continue counter -= block digits.append(1) prior.append(counter - 1) tally = K - 1 for i in range(1, min(len(digits), N - 1)): d = digits[i] if d == 1: tally += (N - i - 2) * 2 ** (N - i - 1) + 1 tally += prior[i] tally += sum(digits) print(tally)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Alice recently converted all the positive integers from 1 to 2^{N} - 1 (both inclusive) into binary strings and stored them in an array S. Note that the binary strings do not have leading zeroes. While she was out, Bob sorted all the elements of S in lexicographical increasing order. Let S_{i} denotes the i^{th} string in the sorted array. Alice defined a function F such that F(S_{i}) is equal to the count of 1 in the string S_{i}. For example, F(101) = 2 and F(1000) = 1. Given a positive integer K, find the value of \sum_{i = 1}^K F(S_{i}). String P is lexicographically smaller than string Q if one of the following satisfies: P is a prefix of Q and P \neq Q. There exists an index i such that P_{i} < Q_{i} and for all j < i, P_{j}=Q_{j}. ------ Input Format ------ - The first line will contain an integer T - number of test cases. Then the test cases follow. - The first and only line of each test case contains two integers N and K. ------ Output Format ------ For each test case, output the value \sum_{i = 1}^K F(S_{i}). ------ Constraints ------ $1 ≤ T ≤ 3000$ $1 ≤ N ≤ 50$ $1 ≤ K ≤ 2^{N} - 1$ - Sum of $N$ over all test cases does not exceed $10^{5}$. ----- Sample Input 1 ------ 3 3 2 3 4 3 7 ----- Sample Output 1 ------ 2 5 12 ----- explanation 1 ------ Converting positive integers to Binary Strings: - $1 = 1$ - $2 = 10$ - $3 = 11$ - $4 = 100$ - $5 = 101$ - $6 = 110$ - $7 = 111$ Sorting Binary Strings in lexicographical order: After sorting, the strings will appear in the following order: $[1, 10, 100, 101, 11, 110, 111]$. Test case $1$: $F(S_{1}) + F(S_{2}) = F(1) + F(10) = 1 + 1 = 2$. Test case $2$: $F(S_{1}) + F(S_{2}) + F(S_{3}) + F(S_{4}) = F(1) + F(10) + F(100) + F(101) = 1 + 1 + 1 + 2 = 5$.
def fullcount(k, n): pow2 = pow(2, n) if k <= 0: return 0 if k == 2 * pow2 - 3: return (n - 1) * pow2 + 1 if k < pow2 - 1: return fullcount(k - 1, n - 1) if k >= pow2 - 1: return fullcount(k - pow2, n - 1) + (k - pow2 + 2) + (n - 2) * pow2 // 2 + 1 return 1 / 0 t = int(input()) for i in range(t): c = input().split() n = int(c[0]) k = int(c[1]) print(k + fullcount(k - 2, n - 1))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER RETURN NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER RETURN BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
Alice recently converted all the positive integers from 1 to 2^{N} - 1 (both inclusive) into binary strings and stored them in an array S. Note that the binary strings do not have leading zeroes. While she was out, Bob sorted all the elements of S in lexicographical increasing order. Let S_{i} denotes the i^{th} string in the sorted array. Alice defined a function F such that F(S_{i}) is equal to the count of 1 in the string S_{i}. For example, F(101) = 2 and F(1000) = 1. Given a positive integer K, find the value of \sum_{i = 1}^K F(S_{i}). String P is lexicographically smaller than string Q if one of the following satisfies: P is a prefix of Q and P \neq Q. There exists an index i such that P_{i} < Q_{i} and for all j < i, P_{j}=Q_{j}. ------ Input Format ------ - The first line will contain an integer T - number of test cases. Then the test cases follow. - The first and only line of each test case contains two integers N and K. ------ Output Format ------ For each test case, output the value \sum_{i = 1}^K F(S_{i}). ------ Constraints ------ $1 ≤ T ≤ 3000$ $1 ≤ N ≤ 50$ $1 ≤ K ≤ 2^{N} - 1$ - Sum of $N$ over all test cases does not exceed $10^{5}$. ----- Sample Input 1 ------ 3 3 2 3 4 3 7 ----- Sample Output 1 ------ 2 5 12 ----- explanation 1 ------ Converting positive integers to Binary Strings: - $1 = 1$ - $2 = 10$ - $3 = 11$ - $4 = 100$ - $5 = 101$ - $6 = 110$ - $7 = 111$ Sorting Binary Strings in lexicographical order: After sorting, the strings will appear in the following order: $[1, 10, 100, 101, 11, 110, 111]$. Test case $1$: $F(S_{1}) + F(S_{2}) = F(1) + F(10) = 1 + 1 = 2$. Test case $2$: $F(S_{1}) + F(S_{2}) + F(S_{3}) + F(S_{4}) = F(1) + F(10) + F(100) + F(101) = 1 + 1 + 1 + 2 = 5$.
def solve(n, k): answer = 0 level = 0 curr = n while True: if k <= curr: answer += (level + 1) * k return answer answer += (level + 1) * curr k -= curr i = 1 while k >= 2**i - 1: k -= 2**i - 1 answer += (level + 1) * (2**i - 1) + sol[i] i += 1 if k == 0: return answer level += 1 curr = i sol = [1, 1] for i in range(2, 51): x = i - 1 for j in range(len(sol)): x += 2**j - 1 + sol[j] sol.append(x) t = int(input()) for _ in range(t): n, k = map(int, input().split()) print(solve(n, k))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER RETURN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Alice recently converted all the positive integers from 1 to 2^{N} - 1 (both inclusive) into binary strings and stored them in an array S. Note that the binary strings do not have leading zeroes. While she was out, Bob sorted all the elements of S in lexicographical increasing order. Let S_{i} denotes the i^{th} string in the sorted array. Alice defined a function F such that F(S_{i}) is equal to the count of 1 in the string S_{i}. For example, F(101) = 2 and F(1000) = 1. Given a positive integer K, find the value of \sum_{i = 1}^K F(S_{i}). String P is lexicographically smaller than string Q if one of the following satisfies: P is a prefix of Q and P \neq Q. There exists an index i such that P_{i} < Q_{i} and for all j < i, P_{j}=Q_{j}. ------ Input Format ------ - The first line will contain an integer T - number of test cases. Then the test cases follow. - The first and only line of each test case contains two integers N and K. ------ Output Format ------ For each test case, output the value \sum_{i = 1}^K F(S_{i}). ------ Constraints ------ $1 ≤ T ≤ 3000$ $1 ≤ N ≤ 50$ $1 ≤ K ≤ 2^{N} - 1$ - Sum of $N$ over all test cases does not exceed $10^{5}$. ----- Sample Input 1 ------ 3 3 2 3 4 3 7 ----- Sample Output 1 ------ 2 5 12 ----- explanation 1 ------ Converting positive integers to Binary Strings: - $1 = 1$ - $2 = 10$ - $3 = 11$ - $4 = 100$ - $5 = 101$ - $6 = 110$ - $7 = 111$ Sorting Binary Strings in lexicographical order: After sorting, the strings will appear in the following order: $[1, 10, 100, 101, 11, 110, 111]$. Test case $1$: $F(S_{1}) + F(S_{2}) = F(1) + F(10) = 1 + 1 = 2$. Test case $2$: $F(S_{1}) + F(S_{2}) + F(S_{3}) + F(S_{4}) = F(1) + F(10) + F(100) + F(101) = 1 + 1 + 1 + 2 = 5$.
import sys MAX_DEPTH = 50 def build_lookup_table(): table = [(0) for _ in range(MAX_DEPTH)] for i in range(1, MAX_DEPTH): table[i] = 2 * table[i - 1] + 2 ** (i - 1) cumulative = [(0) for _ in range(MAX_DEPTH)] for i in range(1, MAX_DEPTH): cumulative[i] = cumulative[i - 1] + table[i] return cumulative def get_lexico_ordered_bits(n, k): ret = lexico_ordered_bits(n, k) return [1] + ret def lexico_ordered_bits(n, k): if k <= 1: return [] if k <= 2 ** (n - 1): return [0] + lexico_ordered_bits(n - 1, k - 1) else: return [1] + lexico_ordered_bits(n - 1, k - 2 ** (n - 1)) def solve(bits, n, i, lookup_table): level = n - len(bits) + (i + 1) if i == 0: if bits[i] == 1: child_count = 1 ones_count = 1 if level - 1 >= 0: child_count += 2**level - 1 ones_count += lookup_table[level - 1] return child_count, ones_count else: return 1, 0 if bits[i] == 0: child_count, ones_count = solve(bits, n, i - 1, lookup_table) return child_count + 1, ones_count else: child_count, ones_count = solve(bits, n, i - 1, lookup_table) ones_count += child_count + 1 child_count += 1 if i == len(bits) - 1: return child_count, ones_count child_count += 2**level - 1 if level - 1 >= 0: ones_count += lookup_table[level - 1] return child_count, ones_count lookup_table = build_lookup_table() t = int(sys.stdin.readline()) for _ in range(t): n, k = map(int, sys.stdin.readline().split()) bits_k = get_lexico_ordered_bits(n, k) bits_k.reverse() if k == 1: print(1) else: print(solve(bits_k, n, len(bits_k) - 1, lookup_table)[1])
IMPORT ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR NUMBER RETURN LIST IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER RETURN BIN_OP LIST NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN BIN_OP LIST NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR RETURN NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL 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 VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER
Alice recently converted all the positive integers from 1 to 2^{N} - 1 (both inclusive) into binary strings and stored them in an array S. Note that the binary strings do not have leading zeroes. While she was out, Bob sorted all the elements of S in lexicographical increasing order. Let S_{i} denotes the i^{th} string in the sorted array. Alice defined a function F such that F(S_{i}) is equal to the count of 1 in the string S_{i}. For example, F(101) = 2 and F(1000) = 1. Given a positive integer K, find the value of \sum_{i = 1}^K F(S_{i}). String P is lexicographically smaller than string Q if one of the following satisfies: P is a prefix of Q and P \neq Q. There exists an index i such that P_{i} < Q_{i} and for all j < i, P_{j}=Q_{j}. ------ Input Format ------ - The first line will contain an integer T - number of test cases. Then the test cases follow. - The first and only line of each test case contains two integers N and K. ------ Output Format ------ For each test case, output the value \sum_{i = 1}^K F(S_{i}). ------ Constraints ------ $1 ≤ T ≤ 3000$ $1 ≤ N ≤ 50$ $1 ≤ K ≤ 2^{N} - 1$ - Sum of $N$ over all test cases does not exceed $10^{5}$. ----- Sample Input 1 ------ 3 3 2 3 4 3 7 ----- Sample Output 1 ------ 2 5 12 ----- explanation 1 ------ Converting positive integers to Binary Strings: - $1 = 1$ - $2 = 10$ - $3 = 11$ - $4 = 100$ - $5 = 101$ - $6 = 110$ - $7 = 111$ Sorting Binary Strings in lexicographical order: After sorting, the strings will appear in the following order: $[1, 10, 100, 101, 11, 110, 111]$. Test case $1$: $F(S_{1}) + F(S_{2}) = F(1) + F(10) = 1 + 1 = 2$. Test case $2$: $F(S_{1}) + F(S_{2}) + F(S_{3}) + F(S_{4}) = F(1) + F(10) + F(100) + F(101) = 1 + 1 + 1 + 2 = 5$.
dp = [[0, 0], [2, 1]] out = 0 def count(k, n, s): global out if k <= 0 or n <= 0: return if s: out += k if k == 1: return if k - (1 << n - 1) == 0: out += dp[n - 2][1] return if k - (1 << n - 1) < 0: count(k - 1, n - 1, 0) return out += dp[n - 2][1] count(k - (1 << n - 1), n - 1, 1) def solve(): global out n, k = [int(i) for i in input().split()] while len(dp) < n - 1: x = dp[-1] dp.append([x[0] * 2 + 2, 2 * x[1] + x[0] + 1]) out = 0 count(k, n, 1) print(out) t = int(input()) for i in range(t): solve()
ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN IF VAR VAR VAR IF VAR NUMBER RETURN IF BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER RETURN IF BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Alice recently converted all the positive integers from 1 to 2^{N} - 1 (both inclusive) into binary strings and stored them in an array S. Note that the binary strings do not have leading zeroes. While she was out, Bob sorted all the elements of S in lexicographical increasing order. Let S_{i} denotes the i^{th} string in the sorted array. Alice defined a function F such that F(S_{i}) is equal to the count of 1 in the string S_{i}. For example, F(101) = 2 and F(1000) = 1. Given a positive integer K, find the value of \sum_{i = 1}^K F(S_{i}). String P is lexicographically smaller than string Q if one of the following satisfies: P is a prefix of Q and P \neq Q. There exists an index i such that P_{i} < Q_{i} and for all j < i, P_{j}=Q_{j}. ------ Input Format ------ - The first line will contain an integer T - number of test cases. Then the test cases follow. - The first and only line of each test case contains two integers N and K. ------ Output Format ------ For each test case, output the value \sum_{i = 1}^K F(S_{i}). ------ Constraints ------ $1 ≤ T ≤ 3000$ $1 ≤ N ≤ 50$ $1 ≤ K ≤ 2^{N} - 1$ - Sum of $N$ over all test cases does not exceed $10^{5}$. ----- Sample Input 1 ------ 3 3 2 3 4 3 7 ----- Sample Output 1 ------ 2 5 12 ----- explanation 1 ------ Converting positive integers to Binary Strings: - $1 = 1$ - $2 = 10$ - $3 = 11$ - $4 = 100$ - $5 = 101$ - $6 = 110$ - $7 = 111$ Sorting Binary Strings in lexicographical order: After sorting, the strings will appear in the following order: $[1, 10, 100, 101, 11, 110, 111]$. Test case $1$: $F(S_{1}) + F(S_{2}) = F(1) + F(10) = 1 + 1 = 2$. Test case $2$: $F(S_{1}) + F(S_{2}) + F(S_{3}) + F(S_{4}) = F(1) + F(10) + F(100) + F(101) = 1 + 1 + 1 + 2 = 5$.
a = [(0) for _ in range(51)] a[1] = 1 for i in range(2, 51): a[i] = 2 * a[i - 1] + 2 ** (i - 2) b = [(0) for i in range(51)] for i in range(1, 51): b[i] = b[i - 1] + a[i] def sol(target, n): value = 1 sum1 = 1 num1 = 1 abnum = 2 ** (n - 1) - 1 while value != target: if value + abnum > target: value = value + 1 sum1 = sum1 + num1 n = n - 1 abnum = 2 ** (n - 1) - 1 elif value + abnum < target: value = value + abnum + 1 sum1 = sum1 + num1 * abnum n = n - 1 for u in range(1, n): sum1 = sum1 + b[u] num1 = num1 + 1 sum1 = sum1 + num1 abnum = 2 ** (n - 1) - 1 else: value = value + abnum sum1 = sum1 + num1 * abnum n = n - 1 for u in range(1, n): sum1 = sum1 + b[u] return sum1 t = int(input()) for _ in range(t): n, k = list(map(int, input().strip().split())) print(sol(k, n))
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
t = int(input()) for _ in range(t): n = int(input()) if n == 1: print(2) else: x = "{0:0b}".format(n) x = len(x) c = pow(2, x) if c - n == 1: print(n - pow(2, x - 1)) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
for _ in range(int(input())): n = int(input()) if n == 1: print(2) continue l = n.bit_length() first = 1 << l - 1 second = n ^ first if first - second == 1: print(second) else: print(-1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
t = int(input()) while t: t -= 1 n = int(input()) if n == 1: print(2) elif n + 1 & n: print(-1) else: print(n >> 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
try: t = int(input()) while t > 0: n = int(input()) if n == 1: print(2) continue if n // 2 ^ n // 2 + 1 == n: print(n // 2) else: print(-1) t -= 1 except: pass
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
t = int(input()) while t: n = int(input()) if n == 1: ans = 2 else: p = n p += 1 flag = 0 while p > 1: if p % 2 == 1: flag = 1 p = p / 2 if flag == 0: k = bin(n)[2:].count("1") ans = 2 ** (k - 1) - 1 else: ans = -1 print(ans) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
t = int(input()) while t > 0: n = int(input()) if n == 1: print(2) else: q = 0 for i in range(1, 31): p = 1 << i if p ^ p - 1 == n: print(p - 1) q = 1 break if q == 0: print(-1) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
def xor(): n = int(input()) a = bin(n)[2:] if a.count("0") == 0: if n == 1: print(2) else: print(n >> 1) else: print(-1) def __starting_point(): t = int(input()) while t != 0: xor() t -= 1 __starting_point()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR STRING NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
for _ in range(int(input())): a = int(input()) flag = 0 r = 0 if a == 1: print("2") elif a & a + 1 == 0: print(a // 2) else: print("-1")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
mod = 1000000007 read_int = lambda: int(input().strip()) read_str = lambda: input().strip() read_str_arr = lambda: input().strip().split() read_int_arr = lambda: [int(x) for x in input().strip().split()] def solve(): N = read_int() if N == 1: ans = 2 elif N & N + 1 == 0: ans = N >> 1 else: ans = -1 print(ans) for _ in range(int(input())): solve()
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
t = int(input()) while t != 0: n = int(input()) b = bin(n)[2:] if n == 1: print(2) elif "0" in b: print(-1) else: print((n - 1) // 2) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
a = list() i = 0 while i <= 30: a.append(2**i - 1) i += 1 for i in range(int(input())): n = int(input()) if n == 1: print("2") continue if n not in a: print(-1) else: print(n // 2)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR 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 STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
for _ in range(int(input())): n = int(input()) if n == 1: print(2) else: num_str = bin(n) count = 0 for i in range(2, len(num_str)): if num_str[i] == "0": count += 1 if count == 0: print(n - (n + 1) // 2) else: print(-1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
t = int(input()) for _ in range(t): n = int(input()) if n == 1: print(2) continue if n & n + 1 == 0: x = (n + 1) // 2 - 1 print(x) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
t = int(input()) for _ in range(t): n = int(input()) for m in range(1, 30 + 1): x = 2**m ^ 2**m - 1 y = 2**m ^ 2**m + 1 if x == n: print(2**m - 1) break elif y == n: print(2**m) break else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
t = int(input()) while t: n = int(input()) if n == 1: print(2) t -= 1 continue if n % 2 == 0: print(-1) t = t - 1 continue idx = -1 for i in range(0, 31): if pow(2, i) > n: if pow(2, i) - 1 == n: idx = n // 2 break print(idx) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR NUMBER VAR VAR IF BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
T = int(input()) ans = [] for _ in range(T): N = int(input()) if N == 1: ans.append(2) elif "0" not in bin(N)[2:]: ans.append(N // 2) else: ans.append(-1) for i in ans: print(i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF STRING FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
for _ in range(int(input())): n = int(input()) i, a = 1, 0 if n == 1: print(2) else: while 2**i <= n + 1: if n == 2**i - 1: a = 1 break i += 1 if a == 1: print(n // 2) else: print(-1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
t = int(input()) while t: t -= 1 n = int(input()) bi = bin(n)[2:] c0 = bi.count("0") if c0: print("-1") elif n == 1: print("2") else: print(n // 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
from sys import stdin, stdout def main(): from sys import stdin, stdout inp = stdin.readline out = stdout.write res = [] t = int(inp().strip()) for i in range(t): n = int(inp().strip()) x = n // 2 if n == 1: res.append("2\n") elif x ^ x + 1 == n: res.append(str(x) + "\n") else: res.append("-1\n") for i in range(t): out(res[i]) main()
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
l = [] for k in range(2, 31): l.append(2**k - 1) for i in range(int(input())): n = int(input()) if n == 1: print(2) continue if n in l: print(n // 2) else: print(-1)
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
for _ in range(int(input())): n = int(input()) flag = 0 if n == 1: print("2") else: for i in range(1, 31): if 2**i - 1 == n: flag = 1 t = i break if flag == 0: print("-1") else: print(2 ** (t - 1) - 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
for _ in range(int(input())): n = int(input()) if n == 1: print(2) else: arr = [] i = 0 while True: if 2**i <= n: arr.append(2**i) i += 1 else: break flg = 0 for i in arr: if i ^ i - 1 == n: flg = 1 print(i - 1) break if not flg: print(-1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
valid_n = [(2**i - 1) for i in range(1, 31)] T = int(input()) for tx in range(T): N = int(input()) if N == 1: print(2) elif N in valid_n: print(valid_n[valid_n.index(N) - 1]) else: print(-1)
ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
t = int(input()) ar = [] for i in range(0, 100): ar.append(15 * 2**i + 2**i - 1) for j in range(0, t): n = int(input()) if n == 3: print(1) elif n == 1: print(2) elif n == 7: print(3) elif (n in ar) == True: print(n // 2) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER 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 VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
T = int(input()) for i in range(T): N = int(input()) f = bin(N)[2:] if f.count("0") == 0: if N == 1: print(2) else: print(N >> 1) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR STRING NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
t = int(input()) for i in range(t): k = int(input()) if k % 2 == 0: print(-1) elif k % 2 != 0: c = (k + 1) // 2 if k == c ^ c - 1: if k != 1: print(c - 1) if k == 1: print(2) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
t = int(input()) s = [] for i in range(31): s.append(2**i - 1) for _ in range(t): n = int(input()) if n == 1: print(2) elif n in s: print(n // 2) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
__author__ = "Ronald Kaiser" __email__ = "raios dot catodicos at gmail dot com" def is_2n(n): while n % 2 == 0: n //= 2 return True if n == 1 else False for _ in range(int(input())): N = int(input()) if N == 1: print(2) elif is_2n(N + 1): print(N // 2) else: print(-1)
ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR 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 FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER