• + 28 comments

    A solution in Python 3:

    T = int(input().strip())
    for _ in range(T):
        n , k = map(int , input().split())
        print(k-1 if ((k-1) | k) <= n else k-2)
    

    NOTE:

    Before reading the explanation below , try to find the pattern using a brute force solution.