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

Code

#include <bits/stdc++.h>

int main() {
	int n, m = 0;
	long tulos = 0;
	std::cin >> n;
	std::vector<int> luvut(n);
	for (int i = 0; i < n; ++i) {
		std::cin >> luvut[i];
		m = std::max(m, luvut[i]);
	}
	if (m <= 100) {
		std::unordered_map<int, int> maara;
		for (int luku: luvut) {
			maara[luku] += 1;
		}
		tulos = maara[1] * (maara[1] - 1);
		for (auto a: maara) {
			for (auto b: maara) {
				if (a.first != b.first && std::gcd(a.first, b.first) == 1) {
					tulos += a.second * b.second;
				}
			}
		}
		tulos /= 2;
	} else {
		std::vector<int> luvut_maskilla[256];
		for (int luku: luvut) {
			int bitit = (
				+ (luku %  2 ? 0 : 0x01)
				+ (luku %  3 ? 0 : 0x02)
				+ (luku %  5 ? 0 : 0x04)
				+ (luku %  7 ? 0 : 0x08)
				+ (luku % 11 ? 0 : 0x10)
				+ (luku % 13 ? 0 : 0x20)
				+ (luku % 17 ? 0 : 0x40)
				+ (luku % 19 ? 0 : 0x80)
			);
			for (int b = 0; b < 256; ++b) {
				if (!(bitit & b)) {
					for (int j: luvut_maskilla[b]) {
						if (std::gcd(luku, j) == 1) {
							tulos += 1;
						}
					}
				}
			}
			luvut_maskilla[bitit].push_back(luku);
		}
	}
	std::cout << tulos << std::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:

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

correct output
3039650753

user output
(empty)

Test 5

Group: 3

Verdict:

input
100000
238907 151373 522599 885657 37...

correct output
3031155756

user output
(empty)

Test 6

Group: 3

Verdict: ACCEPTED

input
100000
510510 510510 510510 510510 51...

correct output
0

user output
0

Test 7

Group: 3

Verdict:

input
100000
999983 999983 999983 999983 99...

correct output
0

user output
(empty)