CSES - Putka Open 2020 – 4/5 - Results
Submission details
Task:Tekijät
Sender:Gomhog
Submission time:2020-11-06 19:30:18 +0200
Language:C++ (C++11)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED12
#2ACCEPTED35
#3ACCEPTED53
Test results
testverdicttimegroup
#1ACCEPTED0.35 s1, 2, 3details
#2ACCEPTED0.35 s1, 2, 3details
#3ACCEPTED0.35 s2, 3details
#4ACCEPTED0.35 s3details
#5ACCEPTED0.39 s3details
#6ACCEPTED0.48 s3details
#7ACCEPTED0.35 s3details

Code

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define F first
#define S second

using namespace std;

const int N=1e6;
vector<int> fact[N+1];
ll cnt[N+1];

void incr(int k, int ind, int cur) {
	if (ind==(int)fact[k].size()) {
		cnt[cur]++;
		return;
	}
	incr(k,ind+1,cur);
	incr(k,ind+1,cur*fact[k][ind]);
}

ll get(int k, int ind, int cur) {
	if (ind==(int)fact[k].size()) return cnt[cur];
	return get(k,ind+1,cur)-get(k,ind+1,cur*fact[k][ind]);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int k=2;k<=N;k++) {
		if (fact[k].size()==0) {
			for (int j=1;j*k<=N;j++) fact[j*k].push_back(k);
		}
	}
	int n;
	cin>>n;
	ll res=0;
	for (int i=0;i<n;i++) {
		int x;
		cin>>x;
		res+=get(x,0,1);
		incr(x,0,1);
	}
	cout<<res<<"\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: 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