CSES - Putka Open 2020 – 4/5 - Results
Submission details
Task:Tekijät
Sender:ArktinenKarpalo
Submission time:2020-11-07 18:46:57 +0200
Language:C++17
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED12
#2ACCEPTED35
#3ACCEPTED53
Test results
testverdicttimegroup
#1ACCEPTED0.04 s1, 2, 3details
#2ACCEPTED0.04 s1, 2, 3details
#3ACCEPTED0.07 s2, 3details
#4ACCEPTED0.09 s3details
#5ACCEPTED0.14 s3details
#6ACCEPTED0.35 s3details
#7ACCEPTED0.07 s3details

Compiler report

input/code.cpp: In function 'long long int brute(std::vector<long long int>)':
input/code.cpp:138:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<v.size(); i++) {
               ~^~~~~~~~~
input/code.cpp:139:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=i+1; j<v.size(); j++)
                  ~^~~~~~~~~

Code

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define M 1000000007
 
using namespace std;

vector<ll> P;
int c = 0;
int prm[1010101];
ll ans = 0;

vector<ll> tek[1010101];

bool prime(ll x) {
	return !prm[x];
}

int z[1010101];
ll cnt[1010101];
vector<ll> dh;


vector<ll> vi[10];
vector<int> vi2[10][222];
void haku2(ll s, ll pr, ll d) {
	int sz = tek[pr].size();
	int nm = (1<<sz);
	assert(nm>1);
	int qq[nm];
	for(int i=0; i<nm; i++)
		qq[i] = 0;
	for(auto i:vi[sz]) {
		ll lk = 1;
		for(ll j=0; j<sz; j++) {
			if((i&(1<<j)))
				lk *= tek[pr][j];
		}
		int lol = 0;
		for(auto u:vi2[sz][i]) {
			lol += qq[u];
		}
/*		for(int j=i+1; j<nm; j++) {
			if((j|i) ==j) {
				lol += qq[j];
			}
		}*/
		qq[i] += cnt[lk]-lol;
		ans -= qq[i];
		cnt[lk]++;
	}
}
ll cnttt;
void haku1(ll s, ll pr, ll d) {
	ll d2 = d;
	queue<int> q;
	queue<int> q2;
	q2.push(s);
	vector<pair<int,int>> dv;
	map<int,int> mp;
lol:
	d += d2;
	d2 = 0;
	q = q2;
	q2 = {};
	while(!q2.empty())
		q2.pop();
	while(!q.empty()) {
		s = q.front();
		q.pop();
		int qq = 0;
		for(auto u:mp) {
			if(u.first%s == 0)
			qq +=u.second;
		}
		ll lk = cnt[s]-qq;
		ans -= lk;
		cout << pr << " " <<s << " " << lk<<endl;
		cnt[s]++;
	//	assert(s>1);
		if(lk)
			mp[s]+=lk;
		for(auto u:tek[pr]) {
			if(u < s && s%u == 0) {
				if(z[s/u] == c) {
					continue;
				} else {
					z[s/u] = c;
				}
				q2.push(s/u);
			}
		}
	
	}
	if(!q2.empty()) {
		goto lol;
	}
}

int cntt = 0;
int mx = 0;
void pr(ll x) {
	ll sm = 1;
	if(x == 1)
		return;
	vector<ll> v;
	if(prime(x)) {
		sm = x;
		v.push_back(x);
	} else {
		while(x > 1) {
			ll lk = prm[x];
			if(lk == 0) {
				if((v.size() == 0 || v[v.size()-1] != x)) {
			sm *= x;
			v.push_back(x);
				}
				break;
			}
			if(v.size() == 0 || v[v.size()-1] != lk) {
			sm *= lk;
			v.push_back(lk);
			}
			x /= lk;
		}
	}
/*	for(auto u:v)
		cout << u<< " . ";
	cout<<endl;*/
	tek[sm] = v;
	haku2(sm, sm, 0);
	//cnt[sm]++;
}


ll brute(vector<ll> v) {
	ll ret = 0;
	for(int i=0; i<v.size(); i++) {
		for(int j=i+1; j<v.size(); j++)
			if(__gcd(v[i], v[j]) == 1)
				ret++;
	}
	return ret;
}

int main() {
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio();
	for(int i=1; i<8; i++) {
		for(int j=i; j>=1; j--) {
			for(int g=1; g<(1<<i); g++) {
				if(__builtin_popcount(g) == j) {
					vi[i].push_back(g);
				}
			}
		}
/*		for(int j=i+1; j<nm; j++) {
			if((j|i) ==j) {
				lol += qq[j];
			}
		}*/
			
		for(int g=1; g<(1<<i); g++) {
			for(int j=g+1; j<(1<<i); j++) {
				if((j|g) ==j) {
					vi2[i][g].push_back(j);
				}
			}
		}
	}
	prm[1] = 1;
	for(ll i=2; i<=1000000; i++) {
		if(!prm[i]) {
			P.push_back(i);
			for(ll j=2; j*i<=1e6; j++)
				if(!prm[i*j])
					prm[i*j] = i;
		}
	}
	ll n;
	cin >> n;
	ans = n*(n-1)/2;
	vector<ll> bv;
	for(int i=0; i<n; i++) {
		int x;
		cin >> x;
		bv.push_back(x);
		c = i+1;
		pr(x);
	}
	cnt[1] = 0;

	cout << ans << endl;
	//cout << ans << 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: 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