forked from gopalgoel19/Competitive-Programming-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoalp.cpp
109 lines (89 loc) · 2.21 KB
/
moalp.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*************************************************************
Created by shivaank
**************************************************************/
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
//keycode 87 = KP_End KP_1 KP_End KP_1
typedef long long ll;
typedef vector<int> vi;
//#define x first
//#define y second
typedef vector<ll> vll;
typedef pair<ll, ll>ii;
typedef pair<ll, ll>mypair;
typedef vector<ii> vii;
typedef set<ll> sll;
typedef map<string, ll> msl;
#define rep(i, a, b) \
for (int i = int(a); i < int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion
#define mod 1000000007
#define mx 200001
string decToHexa(ll n)
{
// char array to store hexadecimal number
string hexa;
// counter for hexadecimal number array
while(n!=0)
{
// temporary variable to store remainder
ll temp = 0;
// storing remainder in temp variable.
temp = n % 16;
// check if temp < 10
if(temp < 10)
{
hexa += (temp + 48);
}
else
{
hexa += (temp + 55);
}
n = n/16;
}
// printing hexadecimal number array in reverse order
return hexa;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t,n,k,ctr = 0,r, sum=1, m,flag = 0,x,y,a=0,b=0,c=0,d,ind,q,curr,ans=0,i,found,first;
ll l;
string s,temp;
unordered_map<int, int>mymap;
unordered_map<int, int> ::iterator itr;
mymap[0] = 0;
std::stringstream stream;
for(int i = 1;i<=2000000;i++)
{
s = decToHexa(i);
ctr = 0;
//cout<<s<<" ";
rep(j,0,s.size())
{
if(s[j]>= 'A' && s[j]<='F')
ctr++;
}
mymap[i] = ctr;
if(i>1)
mymap[i] += mymap[i-1];
//cout<<i<<" : "<<mymap[i]<<"\n";
}
cin>>t;
while(t--)
{
cin>>l>>r;
if(l == 1)
cout<<mymap[r]<<"\n";
else
cout<<mymap[r] - mymap[l-1]<<"\n";
}
return 0;
}