-
Notifications
You must be signed in to change notification settings - Fork 1
/
uva_10990.cpp
47 lines (39 loc) · 874 Bytes
/
uva_10990.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
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i = a, _b = b; i < _b; ++i)
#define FOR(i, a, b) for(int i = a, _b = b; i <= b; ++i)
#define FORD(i, a, b) for(int i = a, _b = b; i >= b; --i)
using namespace std;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef long long llong;
const int MX = 2000001;
int phi[MX], DF[MX], SODF[MX];
void init () {
REP(i, 2, MX) phi[i] = i;
REP(i, 2, MX) {
if(phi[i] == i) {
for(int j = i; j < MX; j += i) {
phi[j] = phi[j]/i*(i-1);
}
}
}
REP(i, 2, MX) {
DF[i] = DF[phi[i]] + 1;
SODF[i] = SODF[i-1] + DF[i];
}
}
int main() {
#ifndef Home
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
init();
int tc;
scanf("%d", &tc);
while(tc--) {
int l, r;
scanf("%d %d", &l, &r);
printf("%d\n", SODF[r] - SODF[l-1]);
}
return 0;
}