-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBits.cpp
More file actions
44 lines (40 loc) · 764 Bytes
/
Bits.cpp
File metadata and controls
44 lines (40 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
AUTHOR: Antarikshya Mitra
TIME:
PROBLEM NO:- BITS 484A
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int MOD = 1e9 + 7;
void solve(int &l,int &r)
{
int ans = l;
for(int b = 62; b >=0; b--)
{
if((ans & (1LL << b)) == 0) // If Bit Not Set
{
int candidate = ans | ((1LL << b) - 1); //Set and Check if it lies in range
if(candidate >= l && candidate <= r)
ans = candidate;
}
}
cout<<ans<<endl;
return;
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
cin>>t;
while(t--)
{
int l,r;
cin>>l>>r;
solve(l,r);
}
return 0;
}