Heading ##There are two integers A and B. You are required to compute the bitwise AND…
- User
Heading ##There are two integers A and B. You are required to compute the bitwise AND amongst all natural numbers lying between A and B, both inclusive. Input Format
First line of the input contains T, the number of testcases to follow. Each testcase in a newline contains A and B separated by a single space.
Constraints
1≤T≤200
0≤A≤B<232
Output Format
Output one line per test case with the required bitwise AND.
SAMPLE INPUT 3 12 15 2 3 8 13
SAMPLE OUTPUT 12 2 8
Explanation
1st Test Case : 12 & 13 & 14 & 15 = 12
2nd Test Case : 2 & 3 = 2
3rd Test Case : 8 & 9 & 10 & 11 & 12 & 13 = 8
Assistant
import sys def compute_bitwise_and(A, B): if A == B: return A xor = A ^ B shift = xor.bit_length() - 1 mask = (-1 << (shift + 1)) return A & mask T = int(sys.stdin.readline()) for _ in range(T): A, B = map(int, sys.stdin.readline().split()) print(compute_bitwise_and(A, B))
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.