Task: | Tekijät |
Sender: | tykkipeli |
Submission time: | 2020-11-06 21:24:06 +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.12 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.12 s | 1, 2, 3 | details |
#3 | ACCEPTED | 0.14 s | 2, 3 | details |
#4 | ACCEPTED | 0.24 s | 3 | details |
#5 | ACCEPTED | 0.37 s | 3 | details |
#6 | ACCEPTED | 0.34 s | 3 | details |
#7 | ACCEPTED | 0.14 s | 3 | details |
Code
#include <bits/stdc++.h> using namespace std; typedef long long ll; void testCase() { } int sieve[2000001]; ll x[1000000]; ll occ[1000001]; bool seen[1000001]; vector<int> divisors[1100001]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); /* int t; cin >> t; for (int i = 0; i < t; i++) { testCase(); } */ int n; cin >> n; for (int i = 0; i < n; i++) cin >> x[i]; for (int i = 0; i < n; i++) seen[x[i]] = true; for (int i = 2; i <= 1100000; i++) { divisors[i].push_back(i); for (int j = 2*i; j <= 1100000; j += i) { if (!sieve[i]) sieve[j] = i; if (seen[j]) divisors[j].push_back(i); } } for (int i = 0; i < n; i++) { for (int a : divisors[x[i]]) occ[a]++; } ll ans = 0; for (int i = 0; i < n; i++) { if (x[i] == 1) { continue; } vector<int> pf; while (sieve[x[i]]) { int a = sieve[x[i]]; pf.push_back(a); while (x[i] % a == 0) x[i] /= a; } if (x[i] > 1) pf.push_back(x[i]); int k = pf.size(); for (int ii = 1; ii < (1<<k); ii++) { int product = 1; for (int j = 0; j < k; j++) { if (ii & (1<<j)) { product *= pf[j]; } } if (__builtin_popcount(ii)%2 == 1) { ans += occ[product]-1; } else { ans -= occ[product]-1; } } } ans /= 2; cout << (ll)n*(n-1)/2 - ans << endl; }
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 |