| Task: | Tekijät |
| Sender: | rasastusni |
| Submission time: | 2020-11-08 19:17:08 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 12 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 12 |
| #2 | WRONG ANSWER | 0 |
| #3 | WRONG ANSWER | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #2 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #3 | WRONG ANSWER | 0.05 s | 2, 3 | details |
| #4 | WRONG ANSWER | 0.14 s | 3 | details |
| #5 | WRONG ANSWER | 0.27 s | 3 | details |
| #6 | WRONG ANSWER | 0.53 s | 3 | details |
| #7 | WRONG ANSWER | 0.11 s | 3 | details |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:56: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);
unordered_map<int, int> counts;
unordered_map<int, int> parity;
long long 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;
++counts[new_product];
parity[new_product] = new_count % 2;
products.push_back({new_count, new_product});
}
}
//cout << i << endl;
//for (auto p : products) {
// cout << p.first << " " << p.second << endl;
//}
}
//cout << "---" << endl;
for (auto x : counts) {
//cout << x.first << " " << x.second << " " << parity[x.first] << endl;
//cout << x.second * (x.second - 1) / 2 << endl;
if (parity[x.first] == 1) {
ans -= (long long)x.second * ((long long)x.second - 1) / 2;
} else {
ans += (long long)x.second * ((long long)x.second - 1) / 2;
}
}
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: WRONG ANSWER
| input |
|---|
| 100000 66 87 90 67 93 89 57 29 34 4 8... |
| correct output |
|---|
| 3044751906 |
| user output |
|---|
| -1250215390 |
Test 4
Group: 3
Verdict: WRONG ANSWER
| input |
|---|
| 100000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
| correct output |
|---|
| 3039650753 |
| user output |
|---|
| -1255316543 |
Test 5
Group: 3
Verdict: WRONG ANSWER
| input |
|---|
| 100000 238907 151373 522599 885657 37... |
| correct output |
|---|
| 3031155756 |
| user output |
|---|
| -1263811540 |
Test 6
Group: 3
Verdict: WRONG ANSWER
| input |
|---|
| 100000 510510 510510 510510 510510 51... |
| correct output |
|---|
| 0 |
| user output |
|---|
| -4294967296 |
Test 7
Group: 3
Verdict: WRONG ANSWER
| input |
|---|
| 100000 999983 999983 999983 999983 99... |
| correct output |
|---|
| 0 |
| user output |
|---|
| -4294967296 |
