-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path546D.cpp
More file actions
65 lines (46 loc) · 900 Bytes
/
546D.cpp
File metadata and controls
65 lines (46 loc) · 900 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
63
64
65
#include <bits/stdc++.h>
using namespace std;
int mfp[6000001];
int psum[6000000];
void crivo(){
for(register int i=2;i<=sqrt(6000000);i++){
if(mfp[i]==i){
for(register int j=i*i;j<=6000000;j+=i){
mfp[j] = min(mfp[j],i);
}
}
}
}
int cont_fat(int v){
int ans = 0;
while(v != 1){
ans++;
v = v/mfp[v];
}
return ans;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for(register int i=0;i<6000000;i++) mfp[i] = i;
mfp[0] = -1;
mfp[1] = -1;
crivo();
int n;
cin >> n;
psum[1] = 0;
for(register int i=2;i<6000000;i++){
psum[i] = psum[i-1] + cont_fat(i);
// if(i<=6){
// cout << cont_fat(i) << endl;
// }
}
//cout << "CHEGOU\n";
for(register int i=0;i<n;i++){
int a,b;
cin >> a >> b;
cout << psum[a] - psum[b] << "\n";
}
return 0;
}