-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanotherNewFunction_UVA10990OJ.cpp
90 lines (74 loc) · 1.71 KB
/
anotherNewFunction_UVA10990OJ.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
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
const long long N = 2000000;
long long phi(long long n, vector<long long> & primes)
{
long long ans = 1, size0 = primes.size();
for (int i = 0; primes[i] * primes[i] <= n && i <= size0 - 1; ++i)
{
long long now = primes[i];
if (n % now == 0)
{
ans *= now - 1;
n /= now;
while (n % now == 0)
{
ans *= now;
n /= now;
}
}
}
if (n > 1)
{
ans *= n - 1;
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
vector<bool> isPrime(1415 + 1, true);
isPrime[0] = false, isPrime[1] = false;
vector<long long> primes;
for (long long i = 2; i <= 1415; ++i)
{
if (isPrime[i] == true)
{
primes.push_back(i);
for (long long j = i * i; j <= 1415; j += i)
{
isPrime[j] = false;
}
}
}
vector<long long> depthphi(N + 1, 1);
for (long long n = 3; n <= N; ++n)
{
long long ans = 0;
depthphi[n] = depthphi[phi(n, primes)] + 1;
}
int T; cin >> T;
for (int t = 1; t <= T; ++t)
{
int m, n; cin >> m >> n;
long long ans = 0;
for (int i = m; i <= n; ++i)
{
ans += depthphi[i];
}
cout << ans << '\n';
}
cout.flush();
return 0;
}