CSES - Putka Open 2020 – 4/5 - Results
Submission details
Task:Tekijät
Sender:Lieska
Submission time:2020-11-06 20:12:51 +0200
Language:C++ (C++17)
Status:READY
Result:12
Feedback
groupverdictscore
#1ACCEPTED12
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.06 s1, 2, 3details
#2ACCEPTED0.05 s1, 2, 3details
#30.07 s2, 3details
#40.08 s3details
#50.09 s3details
#6ACCEPTED0.20 s3details
#7ACCEPTED0.07 s3details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:37:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int k=0; k<v.size(); ++k){
                           ~^~~~~~~~~

Code

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int t[1111000], jakajia[1111000], r[1111000], pot2[11];


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //Älä käytä, jos tehtävä on interaktiivinen!
    for (int i=2; i<=1000000; ++i){
        if (t[i]==0){
            jakajia[i]=1;
            for (int j=i*2; j<=1000000; j+=i) {
                t[j]=i;
                jakajia[j]++;
            }
        }
    }
    pot2[1]=2;
    for (int i=2; i<=10; ++i) pot2[i]=pot2[i-1]*2;
    int n;
    cin >> n;
    int a;
    for (int i=1; i<=n; ++i){
        cin >> a;
        vector<int> v;
        while (t[a]){
            if (v.size()==0 || v[v.size()-1]!=t[a]) v.push_back(t[a]);
            a = a/t[a];
        }
        if (a>1 && (v.size()==0 || v[v.size()-1]!=a)) v.push_back(a);
        for (int j=1; j<pot2[v.size()]; ++j){
            int b=1;
            for (int k=0; k<v.size(); ++k){
                if (j&(1<<k)){
                    b*=v[k];
                }
            }
            r[b]++;
        }
    }
    ll yhttek=0;
    for (int i=2; i<=1000000; ++i){
        if (jakajia[i]%2==1) yhttek+=r[i]*(r[i]-1)/2;
        else yhttek-=r[i]*(r[i]-1)/2;
    }
    cout << n*(n-1)/2-yhttek << "\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:

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

correct output
3044751906

user output
897268258

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
892167105

Test 5

Group: 3

Verdict:

input
100000
238907 151373 522599 885657 37...

correct output
3031155756

user output
883672108

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