Task: | Tekijät |
Sender: | Olli |
Submission time: | 2020-11-06 18:24:00 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 12 |
#2 | ACCEPTED | 35 |
#3 | ACCEPTED | 53 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.06 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.06 s | 1, 2, 3 | details |
#3 | ACCEPTED | 0.09 s | 2, 3 | details |
#4 | ACCEPTED | 0.11 s | 3 | details |
#5 | ACCEPTED | 0.14 s | 3 | details |
#6 | ACCEPTED | 0.31 s | 3 | details |
#7 | ACCEPTED | 0.10 s | 3 | details |
Code
#include <iostream> #include <fstream> #include <vector> #include <algorithm> #include <queue> #include <stack> #include <set> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define F first #define S second #define X first #define Y second const int N = 1e6 + 5; const ll INF = 1e18; ll am[N]; bool pr[N]; int gpd[N]; ll mo[N]; void sieve() { for(int i = 2; i < N; ++i) { pr[i] = true; } for(ll i = 2; i < N; ++i) { if(!pr[i]) continue; gpd[i] = i; for(ll j = 2*i; j < N; j+=i) { gpd[j] = i; pr[j] = false; } } } void add(int x, int d) { if(x == 1) { ++am[d]; return; } int p = gpd[x]; int X = x; int e = 0; while(X%p == 0) { ++e; X/=p; } int c = 1; for(int i = 0; i <= e; ++i) { add(X, d*c); c *= p; } } int main() { sieve(); mo[1] = 1; for(int i = 2; i < N; ++i) { ll p = gpd[i]; if(i%(p*p) == 0) { mo[i] = 0; } else { mo[i] = -mo[i/p]; } } int n; cin >> n; for(int i = 1; i <= n; ++i) { int x; cin >> x; add(x, 1); } ll ans = 0; for(int i = 1; i < N; ++i) { ans += mo[i] * (am[i] * am[i] - am[i]); } cout << ans/2 << "\n"; }
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
3043 |
user output |
---|
3043 |
Test 2
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 71 19 26 18 57 78 80 89 31 26 ... |
correct output |
---|
3086 |
user output |
---|
3086 |
Test 3
Group: 2, 3
Verdict: ACCEPTED
input |
---|
100000 66 87 90 67 93 89 57 29 34 4 8... |
correct output |
---|
3044751906 |
user output |
---|
3044751906 |
Test 4
Group: 3
Verdict: ACCEPTED
input |
---|
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
correct output |
---|
3039650753 |
user output |
---|
3039650753 |
Test 5
Group: 3
Verdict: ACCEPTED
input |
---|
100000 238907 151373 522599 885657 37... |
correct output |
---|
3031155756 |
user output |
---|
3031155756 |
Test 6
Group: 3
Verdict: ACCEPTED
input |
---|
100000 510510 510510 510510 510510 51... |
correct output |
---|
0 |
user output |
---|
0 |
Test 7
Group: 3
Verdict: ACCEPTED
input |
---|
100000 999983 999983 999983 999983 99... |
correct output |
---|
0 |
user output |
---|
0 |