-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBitwise AND of Numbers Range.cpp
94 lines (89 loc) · 1.43 KB
/
Bitwise AND of Numbers Range.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <unordered_set>
#include <stack>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stdio.h>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
#include <cmath>
#include <math.h>
#include <limits>
#define ll long long int
const ll N = 1e5 + 2, MOD = 1e9 + 7;
using namespace std;
int power(ll a, ll b)
{
ll ans = 1;
while (b > 0)
{
if (b % 2)
{
ans = ans * a;
}
a = a * a;
b >>= 1;
}
return ans;
}
ll countSetBits(ll n)
{
ll count = 0;
while (n)
{
count += n & 1;
n >>= 1;
}
return count;
}
ll gcd(ll a, string b)
{
ll res = 0;
for (int i = 0; i < b.length(); i++)
{
res = ((res * 10) + (b[i] - '0')) % a;
}
return __gcd(a, res);
}
void print(vector<ll> v, ll n)
{
for (ll i = 0; i < n; i++)
{
cout << v[i] << ' ';
}
cout << endl;
}
void solve()
{
ll left;cin>>left;
ll right;cin>>right;
int count = 0;
while (left != right)
{
left >>= 1;
right >>= 1;
count++;
cout<<left<<" "<<right<<" "<<count<<endl;
}
cout<< (left << count);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}