Given two numbers A and B. Find the value of pair (P,Q) such that A <= P < Q <= B value of P AND Q is maximum where AND is a binary operator.
Input:
First line of input contains number of test cases T. Each test case contains two numbers A and B.
Output:
For each test case print the value of maximum AND.
*Constraints: *
1<=T<=1000
1<= A < B <=1018
Sample Input
2
2 3
4 8
Sample Output
2
6
C++ Implementation:
Input:
First line of input contains number of test cases T. Each test case contains two numbers A and B.
Output:
For each test case print the value of maximum AND.
*Constraints: *
1<=T<=1000
1<= A < B <=1018
Sample Input
2
2 3
4 8
Sample Output
2
6
C++ Implementation:
#include <iostream>
using namespace std;
typedef unsigned long long int ll;
ll max(ll a,ll b)
{
if(b-a==1)
return (b&a);
else if(!(b&1))
return ((b-1)&(b-2));
else
return (b&(b-1));
}
int main()
{
ll t;
cin>>t;
ll a,b;
while(t--)
{
cin>>a>>b;
cout<<max(a,b)<<endl;
}
return 0;
}