-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1007.cpp
More file actions
48 lines (46 loc) · 1.07 KB
/
1007.cpp
File metadata and controls
48 lines (46 loc) · 1.07 KB
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
/**
* ____
* ____ ___ ____ ________ __/ __/
* / __ `__ \/ __ `/ ___/ / / / /_
* / / / / / / /_/ / / / /_/ / __/
* /_/ /_/ /_/\__,_/_/ \__,_/_/
*
* @link : https://the-redback.com
*/
#include <bits/stdc++.h>
using namespace std;
#define inf HUGE_VAL
#define mem(a, b) memset(a, b, sizeof(a))
#define NN 5000001
unsigned long long a[NN + 7];
void sieve(void) {
int i, j, k, n = 2237;
for (i = 2; i < NN; i++) a[i] = i;
for (i = 2; i < NN; i += 2) {
a[i] *= (2 - 1);
a[i] /= 2;
}
for (i = 3; i < NN; i += 2)
if (a[i] == i) {
for (j = i; j < NN; j += i) {
a[j] *= (i - 1);
a[j] /= i;
}
}
}
int main() {
sieve();
int tc, t = 1;
int i, j, k, l, x;
for (i = 2; i < NN; i++) {
a[i] *= a[i];
a[i] += a[i - 1];
}
printf("%llu");
scanf("%d", &tc);
while (tc--) {
scanf("%d%d", &k, &l);
printf("Case %d: %llu\n", t++, a[l] - a[k - 1]);
}
return 0;
}