CSES - Putka Open 2020 – 4/5 - Results
Submission details
Task:Tekijät
Sender:Mahtimursu
Submission time:2020-11-07 13:14:08 +0200
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1, 2, 3details
#20.01 s1, 2, 3details
#3--2, 3details
#4--3details
#5--3details
#6--3details
#7--3details

Code

#include <bits/stdc++.h>
typedef long long ll;
#define M 1000000007
using namespace std;
set<int> factors(int n) {
set<int> r;
if (n == 1) {
r.insert(1);
return r;
}
int div = 2;
while (n > 1) {
if (div * div > n) {
r.insert(n);
break;
}
if (n % div == 0) {
r.insert(div);
n /= div;
div = 1;
}
div++;
}
return r;
}
bool ok(set<int> s1, set<int> s2) {
for (int x : s1) {
if (s2.find(x) != s2.end()) return false;
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
vector<set<int>> ft;
for (int i = 0; i < n; ++i) {
ft.push_back(factors(v[i]));
}
ll ans = 0;
for (int i = 0; i < n; ++i) {
ll s = 0;
//cout << "i: " << i << endl;
for (int j = i+1; j < n; ++j) {
if (i == j) continue;
if (ok(ft[i], ft[j])) {
s++;
//cout << "\t" << j << endl;
}
}
if (s > 1) {
ans += s;
}
}
cout << ans << endl;
return 0;
}

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
100
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
3043

user output
3040

Test 2

Group: 1, 2, 3

Verdict:

input
100
71 19 26 18 57 78 80 89 31 26 ...

correct output
3086

user output
3084

Test 3

Group: 2, 3

Verdict:

input
100000
66 87 90 67 93 89 57 29 34 4 8...

correct output
3044751906

user output
(empty)

Test 4

Group: 3

Verdict:

input
100000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
3039650753

user output
(empty)

Test 5

Group: 3

Verdict:

input
100000
238907 151373 522599 885657 37...

correct output
3031155756

user output
(empty)

Test 6

Group: 3

Verdict:

input
100000
510510 510510 510510 510510 51...

correct output
0

user output
(empty)

Test 7

Group: 3

Verdict:

input
100000
999983 999983 999983 999983 99...

correct output
0

user output
(empty)