-
Notifications
You must be signed in to change notification settings - Fork 34
/
1007-Mathematically-Hard.cpp
111 lines (74 loc) · 1.4 KB
/
1007-Mathematically-Hard.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>
#include <vector>
#include <stdio.h>
#define N 5000000
#include <string.h>
using namespace std;
unsigned long long ans[N+5];
bool isprime[N+5];
int prime()
{
memset(isprime, 1, sizeof(isprime));
for(int i = 2; i <= N; i++) {
if(isprime[i] == 1) {
for (int j = i + i; j <= N; j = j + i) {
isprime[j] = 0;
}
}
}
}
int main()
{
vector <int> x;
ans[0] = 0;
ans[1] = 0;
int count = 0;
unsigned long long a;
unsigned long long b;
unsigned long long temp;
unsigned long long pr;
unsigned long long t;
unsigned long long j;
unsigned long long div;
prime();
for (int i = 2; i <= N; i++) {
if(isprime[i]) {
x.push_back(i);
}
}
for (int i = 0; i <= N; i++) {
ans[i] = i;
}
for (int i = 0; i < x.size(); i++) {
pr = x[i];
div = 1;
for (int j = pr; j <= N; j = j + pr) {
ans[j] =(((ans[j] * (pr - 1)))/ pr);
}
}
for (int i = 1; i <= N; i++) {
ans[i] = ans[i] * ans[i];
ans[i] += ans[i-1];
}
cin >> t;
for (int i =1 ; i <= t; i++) {
scanf("%lld", &a);
scanf("%lld", &b);
temp = ans[b] - ans[a-1];
printf("Case %d: %llu\n",i, temp);
}
}
&t);
ll cases = t;
pregenerate();
while(t--){
ll a,b;
// cin >> a >> b;
scanf("%lld %lld",&a,&b);
ll ans = dp[b] - dp[a-1];
// cout << "Case " << cases - t << ": " << ans << endl;
printf("Case ");
printf("%lld: %llu\n",cases-t,ans);
}
return 0;
}