forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.cpp
More file actions
52 lines (42 loc) · 941 Bytes
/
D.cpp
File metadata and controls
52 lines (42 loc) · 941 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
45
46
47
48
49
50
51
52
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <map>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <sstream>
#define FOR(i, a, b) for(int i=(a), _b=(b); i<=_b; i++)
#define DOW(i, a, b) for(int i=(a), _b=(b); i>=_b; i--)
#define REP(i, b) for(int i=0; i<b; i++)
#define PB push_back
#define CT(x) ((x) << 1)
#define CP(x) (CT(x) + 1)
#define MAXN 50111
using namespace std;
int main() {
ios::sync_with_stdio(0);
long long l, r;
while (cin >> l >> r) {
while (true) {
long long p2 = 1;
while (p2*2 <= r) p2 *= 2;
if (l <= p2-1 && p2 <= r) {
cout << p2 * 2 - 1 << endl;
break;
}
else {
l -= p2;
r -= p2;
if (r == 0) {
cout << 0 << endl;
break;
}
}
}
}
return 0;
}