diff --git a/src/bin/a.out b/src/bin/a.out index 0b36096..7aceb09 100755 Binary files a/src/bin/a.out and b/src/bin/a.out differ diff --git a/src/bin/cf-1884d.cc b/src/bin/cf-1884d.cc index 3022b7b..fef9ab0 100644 --- a/src/bin/cf-1884d.cc +++ b/src/bin/cf-1884d.cc @@ -296,30 +296,39 @@ void prep() {} void solve() { read(ll, n); - readvec(int, a, n); - unordered_counter(a, ct); - unordered_map dp; - set> st(a.begin(), a.end()); + vector ct(n + 1); + vector has(n + 1); + for (int i = 0; i < n; ++i) { + read(int, x); + ct[x] += 1; + } + for (int x = 1; x <= n; ++x) { + if (!ct[x]) continue; + for (ll y = x; y <= n; y += x) { + has[y] = 1; + } + } + vector dp(n + 1); ll res = 0; - for (auto&& x : st) { + // enumerate gcd(a[i], a[j]) =: x + for (int x = n; x; --x) { + if (!has[x]) continue; + // cerr << x << ' '; ll curr = 0; for (ll y = x; y <= n; y += x) { - if (ct.count(y)) { - curr += ct[y]; - } + curr += ct[y]; } curr = curr * (curr - 1) / 2; for (ll y = x; y <= n; y += x) { - if (dp.count(y)) { - curr -= dp[y]; - } + curr -= dp[y]; } dp[x] = curr; res += curr; } - for (auto&& [x, y] : dp) { - cerr << "dp[" << x << "] = " << y << endl; - } + // cerr << endl; + // for (auto&& [x, y] : dp) { + // cerr << "dp[" << x << "] = " << y << endl; + // } cout << n * (n - 1) / 2 - res << '\n'; } diff --git a/src/bin/test.py b/src/bin/test.py index 9698d4d..adae31b 100644 --- a/src/bin/test.py +++ b/src/bin/test.py @@ -1,6 +1,19 @@ -from random import randint -print(100000) -for _ in range(2): - for i in range(100000): - print(randint(0, 1), end='') - print() +from typing import DefaultDict + + +n = int(input()) +a = [int(x) for x in input().strip().split(' ')] +d = sorted(list(set(a)), reverse=True) +a.sort() +slot = DefaultDict(lambda: []) +slot_cnt = DefaultDict(lambda: 0) +for i in range(n): + for j in range(i + 1, n): + for k in d: + if a[i] % k == 0 and a[j] % k == 0: + slot[k].append((a[i], a[j])) + slot_cnt[k] += 1 + break + +print(slot) +print(n * (n - 1) // 2 - sum(v for v in slot_cnt.values()))