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

Code

#include <iostream>
using namespace std;
const int MN = 1<<17;
const int MX = 1<<20;
int xs[MN];
int ps[MX];
bool nonp[MX];

int counts[MX];
int fs[32];

int go(int x, int f, int c) {
	if (f<0) return counts[x]++ * c;
	return go(x, f-1, c) + go(x*fs[f], f-1, -c);
}

int main() {
	int P=0;
	for(int i=2; i<MX; ++i) if (!nonp[i]) {
		ps[P++] = i;
		for(int j=2*i; j<MX; j+=i) nonp[j]=1;
	}
	int n;cin>>n;
	long long res=0;
	while(n--) {
		int x;cin>>x;
		int f=0;
		for(int i=0; x>1; ++i) {
			int p = ps[i];
			if (x%p==0) {
				do x/=p; while(x%p==0);
				fs[f++] = p;
			} else if (p*p>x) break;
		}
		if (x>1) fs[f++] = x;
		res += go(1, f-1, 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