-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.cpp
More file actions
95 lines (81 loc) · 1.93 KB
/
code.cpp
File metadata and controls
95 lines (81 loc) · 1.93 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
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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define endl '\n'
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define prec(x) fixed << setprecision(x)
#define testcase cout << "Case " << cs++ << ":"
//stol(s);sqrtl() to_string(x);
template <typename T>
using minHeap = priority_queue<T, vector<T>, greater<T>>;
const ld PI = acos((ld) - 1);
const int MOD = 1e9 + 7;
const ll INF = 2e18 + 1;
const ld EPS = 1e-9;
const int MX = 1e6 + 5;
int cs = 1;
int mu[MX], freq[MX];
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
void mobius(int limit) {
vector<int> primes;
vector<bool> vis(limit + 1, 0);
mu[1] = 1;
for (int i = 2; i <= limit; ++i) {
if (!vis[i]) {
primes.push_back(i);
mu[i] = -1;
}
for (int p : primes) {
if (i * p > limit) break;
vis[i * p] = 1;
if (i % p == 0) { // ⇒ square factor
mu[i * p] = 0;
break;
} else mu[i * p] = -mu[i];
}
}
}
inline ll C3(ll n) {
if (n < 3) return 0;
return n * (n - 1) * (n - 2) / 6;
}
void solve() {
int n; cin >> n;
vector<int> a(n);
int mx = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i];
freq[a[i]]++;
mx = max(mx, a[i]);
}
mobius(mx);
for (int d = 1; d <= mx; ++d) {
for (int mult = 2*d; mult <= mx; mult += d) {
freq[d] += freq[mult];
}
}
ll ans = 0;
for (int d = 1; d <= mx; ++d) {
ans += (ll)mu[d] * C3(freq[d]);
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//cin >> t;
//cin.ignore();
while (t--) {
solve();
}
return 0;
}