CSES - Putka Open 2020 – 4/5 - Results
Submission details
Task:Tekijät
Sender:ollpu
Submission time:2020-11-06 19:10:32 +0200
Language:C++ (C++17)
Status:READY
Result:12
Feedback
groupverdictscore
#1ACCEPTED12
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.10 s1, 2, 3details
#2ACCEPTED0.10 s1, 2, 3details
#30.10 s2, 3details
#4ACCEPTED0.15 s3details
#5ACCEPTED0.26 s3details
#6ACCEPTED0.23 s3details
#7ACCEPTED0.11 s3details

Code

#include <bits/stdc++.h>
using namespace std;
int z[1010101];
int p[1010101];
int ma[1010101];
vector<int> pa[1010101];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int x[n];
  for (int i = 0; i < n; ++i) cin >> x[i], z[x[i]]++;
  for (int i = 2; i <= 1000000; ++i) {
    bool up = !p[i];
    for (int j = i; j <= 1000000; j += i) {
      p[j] = 1;
      if (up && z[j]) pa[j].push_back(i);
      ma[i] += z[j];
    }
  }
  long res = 0;
  for (int i = 0; i < n; ++i) {
    vector<int> &op = pa[x[i]];
    int opc = op.size();
    long ores = 0;
    for (int m = 1; m < (1<<opc); ++m) {
      int y = 1;
      for (int j = 0; j < opc; ++j) if (m & (1<<j)) y *= op[j];
      long gs = ma[y];
      if (__builtin_parity(m)) ores += gs;
      else ores -= gs;
    }
    res += n-ores;
  }
  cout << res/2 << 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:

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: 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