-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathspecial-sequence.cpp
60 lines (53 loc) · 1.16 KB
/
special-sequence.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
#include<bits/stdc++.h>
#define ll long double
using namespace std;
vector<long long>p;
signed main(){
long long sum = 0;
p.push_back(0);
for(ll i = 1 ; i <= 500000 ; i++){
long long val = i*floor(sqrt(i)) + ceil(i/2);
p.push_back(val);
}
int sz = p.size();
for(int i = 1 ; i < sz ; i++){
p[i] += p[i-1];
}
int q;
cin >> q;
assert(1 <= q and q <= 100000);
while(q--){
long long l, r;
cin >> l >> r;
assert(1 <= l and l <= r and r <= 10000000000000);
int s = 0;
int e = sz - 1;
int ans1 = -1;
while(s <= e){
int m = (s + e)/2;
if(p[m] < l){
ans1 = m;
s = m + 1;
}
else{
e = m - 1;
}
}
ans1++;
s = 0;
e = sz - 1;
int ans2 = -1;
while(s <= e){
int m = (s + e)/2;
if(p[m] < r){
ans2 = m;
s = m + 1;
}
else{
e = m - 1;
}
}
ans2++;
cout << (ans2 - ans1 + 1) << endl;
}
}