CSES - Putka Open 2020 – 4/5 - Results
Submission details
Task:Tekijät
Sender:Metabolix
Submission time:2020-11-07 23:13:35 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

Output limit exceeded in compilation

Code

#include <bits/stdc++.h>

#define N 1000001
int p[N], dp[N] = {0, 1};
long jaettavia[N];

int main() {
	int n;
	for (int i = 2; i < N; ++i) {
		if (!p[i]) for (int j = i; j < N; j += i) {
			if (!p[j]) {
				p[j] = i;
			}
		}
		if (p[i / p[i]] == p[i]) {
			dp[i] = 0;
		} else {
			dp[i] = -1 * dp[i / p[i]];
		}
	}
	std::cin >> n;
	std::vector<int> luvut(n);
	for (int i = 0; i < n; ++i) {
		std::cin >> luvut[i];
		int l = luvut[i];
		for (int j = (int)sqrt(l); j; j--) {
			if (l % j == 0) {
				jaettavia[j] += 1;
				if (j*j != l) {
					jaettavia[l/j] += 1;
				}
			}
		}
	}
	long tulos = 0;
	for (int x = 1; x <= 1000000; ++x) {
		tulos += dp[x] * (jaettavia[x] * (jaettavia[x] - 1) / 2);
	}
	std::cout << tulos << std::endl;
}