-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathiss.cpp
More file actions
41 lines (41 loc) · 752 Bytes
/
Copy pathiss.cpp
File metadata and controls
41 lines (41 loc) · 752 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
#include <bits/stdc++.h>
using namespace std;
int main()
{
cin.tie(0);
int n = 4e6 + 5;
int pi[n], a[n];
for (int i = 0; i < n; i++)
{
pi[i] = i;
a[i] = 0;
}
for (int p = 2; p < n; p++)
{
if (pi[p] == p)
{
pi[p] = p - 1;
for (int i = 2 * p; i < n; i += p)
{
pi[i] = (pi[i] / p) * (p - 1);
}
}
}
for (int i = 1; i < n; i++)
{
a[i] += i - 1;
for (int j = 2 * i; j < n; j += i)
{
a[j] += i * ((1 + pi[j / i]) / 2);
}
}
int t;
cin >> t;
while (t--)
{
int k;
cin >> k;
cout << a[4 * k + 1] << "\n";
}
return 0;
}