Task: | Tekijät |
Sender: | jnalanko |
Submission time: | 2020-11-08 22:20:39 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 12 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 12 |
#2 | WRONG ANSWER | 0 |
#3 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#3 | WRONG ANSWER | 0.03 s | 2, 3 | details |
#4 | ACCEPTED | 0.17 s | 3 | details |
#5 | TIME LIMIT EXCEEDED | -- | 3 | details |
#6 | TIME LIMIT EXCEEDED | -- | 3 | details |
#7 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
#include <iostream> #include <vector> //#include "stdlib_printing.hh" typedef long long LL; using namespace std; int main(){ LL n; cin >> n; vector<LL> v(n); LL xmax = 0; for(LL i = 0; i < n; i++){ cin >> v[i]; xmax = max(xmax, v[i]); } vector<bool> isprime(xmax+1,true); isprime[0] = false; isprime[1] = false; vector<vector<LL> > PD(xmax+1); // C[i] = Distinct prime divisors of i vector<vector<LL> > D(xmax+1); // D[i] = Divisors of i vector<LL> C(xmax+1); // C[i] = Number of items in the input that are divisible by i for(LL d = 2; d <= xmax; d++){ for(LL k = 1; d*k <= xmax; k++){ D[d*k].push_back(d); if(isprime[d]) PD[d*k].push_back(d); if(k > 1) isprime[k*d] = false; } } for(LL x : v){ for(LL d : D[x]) C[d]++; } LL ans = 0; for(LL x : v){ LL m = PD[x].size(); LL howmany = 0; for(LL mask = 1; mask < (1LL << m); mask++){ LL ones = __builtin_popcount(mask); LL sign = ones % 2 == 1 ? 1 : -1; LL d = 1; for(LL i = 0; i < m; i++){ if(mask & (1LL << i)) d *= PD[x][i]; } howmany += sign * C[d]; } ans += n - howmany; } cout << ans/2 << endl; // Divide by two because we report unordered pairs //cout << isprime << endl; //cout << PD << endl; //cout << D << endl; //cout << C << 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: WRONG ANSWER
input |
---|
100000 66 87 90 67 93 89 57 29 34 4 8... |
correct output |
---|
3044751906 |
user output |
---|
3044752431 |
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: TIME LIMIT EXCEEDED
input |
---|
100000 238907 151373 522599 885657 37... |
correct output |
---|
3031155756 |
user output |
---|
(empty) |
Test 6
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 510510 510510 510510 510510 51... |
correct output |
---|
0 |
user output |
---|
(empty) |
Test 7
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 999983 999983 999983 999983 99... |
correct output |
---|
0 |
user output |
---|
(empty) |