-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSPCO-21823185-src.cpp
More file actions
62 lines (62 loc) · 882 Bytes
/
SPCO-21823185-src.cpp
File metadata and controls
62 lines (62 loc) · 882 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
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <algorithm>
#define ulli unsigned long long int
using namespace std;
ulli nCr[65][66];
int primes[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61,67};
void build()
{
int i,j;
nCr[0][0]=1;
for(i=1;i<65;i++)
{
nCr[i][0]=nCr[i][i]=1;
for(j=1;j<i;j++)nCr[i][j]=nCr[i-1][j-1]+nCr[i-1][j];
}
}
int kitni_bits(ulli no)
{
int ret=0;
while(no)
{
if(no&1)ret++;
no>>=1;
}
return ret;
}
ulli solve(ulli no)
{
int pos=0;
int shift=kitni_bits(no)-1;
//cout<<shift;
ulli answer=0;
while(no)
{
if(no&1)
{
int r=2-shift;
for(int i=0;i<19 && pos>=r;i++)
{
if(r>=0)answer+=nCr[pos][r];
r=primes[i+1]-shift;
}
shift--;
}
no>>=1;
pos++;
}
return answer;
}
int main()
{
build();
int t;
ulli a,b,ans;
cin>>t;
while(t--)
{
cin>>a>>b;
ans=solve(b+1)-solve(a);
cout<<ans<<"\n";
}
}