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

Code

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define F first
#define S second
#define X first
#define Y second

const int N = 1e6 + 5;
const ll INF = 1e18;

ll am[N];
bool pr[N];
int gpd[N];

ll mo[N];

void sieve() {
	for(int i = 2; i < N; ++i) {
		pr[i] = true;
	}
	for(ll i = 2; i < N; ++i) {
		if(!pr[i]) continue;
		gpd[i] = i;
		for(ll j = 2*i; j < N; j+=i) {
			gpd[j] = i;
			pr[j] = false;
		}
	}
}


void add(int x, int d) {
	if(x == 1) {
		++am[d];
		return;
	}

	int p = gpd[x];
	int X = x;
	int e = 0;
	while(X%p == 0) {
		++e;
		X/=p;
	}

	int c = 1;
	for(int i = 0; i <= e; ++i) {
		add(X, d*c);
		c *= p;
	}
}


int main() {
	sieve();

	mo[1] = 1;
	for(int i = 2; i < N; ++i) {
		ll p = gpd[i];
		if(i%(p*p) == 0) {
			mo[i] = 0;
		} else {
			mo[i] = -mo[i/p];
		}
	}


	int n;
	cin >> n;
	for(int i = 1; i <= n; ++i) {
		int x;
		cin >> x;
		add(x, 1);
	}


	ll ans = 0;
	for(int i = 1; i < N; ++i) {
		ans += mo[i] * (am[i] * am[i] - am[i]);
	}

	cout << ans/2 << "\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