题目链接:点击打开题目
把下界的二进制位从低位开始把0变1,直到大于上界为止。
代码如下:
#include<iostream>
#include<cstdio>
using namespace std;
typedef __int64 LL;
int main()
{
int u;
cin >> u;
LL a,b;
LL one=1;
while (u--)
{
cin >> a >> b;
// while (a)
// {
// cout << (a&1);
// a >>= 1;
// }
// cout << endl;
// while (b)
// {
// cout << (b&1);
// b >>= 1;
// }
// cout << endl << endl;
int pos = 0;
while ((a|(one<<pos)) <= b)
{
a |= one << pos;
pos++;
}
cout << (a|b) << endl;
}
return 0;
}