CSES - Putka Open 2020 – 4/5 - Results
Submission details
Task:Tekijät
Sender:rasastusni
Submission time:2020-11-08 14:31:14 +0200
Language:C++17
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1, 2, 3details
#20.01 s1, 2, 3details
#30.04 s2, 3details
#40.08 s3details
#50.12 s3details
#60.18 s3details
#70.10 s3details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:54:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int a = 0; a < round_max; ++a) {
                    ~~^~~~~~~~~~~

Code

#include <iostream>
#include <unordered_map>
#include <vector>

using namespace std;

vector<int> gen_primes(int n) {
	vector<int> result = {2};
	for (int i = 3; i*i <= n; ++i) {
		bool good = true;
		for (auto p : result) {
			if (i % p == 0) {
				good = false;
				break;
			}
		}
		if (good) result.push_back(i);
	}
	return result;
}

vector<int> prime_facts(int x, const vector<int> &primes) {
	vector<int> result;
	for (auto p : primes) {
		if (p > x) break;
		if (x % p == 0) {
			result.push_back(p);
			do {
				x /= p;
			} while (x % p == 0);
		}
	}
	if (x > 1) result.push_back(x);
	return result;
}

int main()
{
	int n;
	cin >> n;
	vector<int> nums(n);
	int maximum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> nums[i];
		maximum = max(maximum, nums[i]);
	}
	auto primes = gen_primes(maximum);
	int ans = n * (n - 1) / 2;
	for (int i = 0; i < n; ++i) {
		auto facts = prime_facts(nums[i], primes);
		vector<pair<int, int>> products = {{0, 1}};
		for (auto f : facts) {
			auto round_max = products.size();
			for (int a = 0; a < round_max; ++a) {
				auto new_count = products[a].first + 1;
				auto new_product = products[a].second * f;
				if (new_count % 2 == 1) --ans;
				products.push_back({new_count, new_product});
			}
		}
	}
	cout << ans << endl;
}

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
100
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
3043

user output
4771

Test 2

Group: 1, 2, 3

Verdict:

input
100
71 19 26 18 57 78 80 89 31 26 ...

correct output
3086

user output
4773

Test 3

Group: 2, 3

Verdict:

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

correct output
3044751906

user output
704804018

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
704593414

Test 5

Group: 3

Verdict:

input
100000
238907 151373 522599 885657 37...

correct output
3031155756

user output
704523658

Test 6

Group: 3

Verdict:

input
100000
510510 510510 510510 510510 51...

correct output
0

user output
698582704

Test 7

Group: 3

Verdict:

input
100000
999983 999983 999983 999983 99...

correct output
0

user output
704882704