Input Format
The first line contains an integer, , the number of test cases.
Each of the subsequent lines defines a test case as space-separated integers, and , respectively.
Constraints
Output Format
For each test case, print the maximum possible value of on a new line.
Sample Input
3
5 2
8 5
2 2
Sample Output
1
4
0
Explanation
All possible values of and are:
The maximum possible value of that is also is , so we print on a new line.
Solution:
import math
import os
import random
import re
import sys
def cal(n,k):
max1=0
a=n
b=k-1
for a in range(n,2,-1):
if(a==b):
continue
if((a&b)>max1):
max1=a&b
return max1
if __name__ == '__main__':
t = int(input())
for t_itr in range(t):
nk = input().split()
n = int(nk[0])
k = int(nk[1])
print(cal(n,k))
0 Comments