Pagini recente » Cod sursa (job #2197028) | Cod sursa (job #3032922) | Cod sursa (job #2575882) | Cod sursa (job #94463) | Cod sursa (job #2766673)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("pairs.in");
ofstream fout("pairs.out");
const int MAXV = 1e6;
bitset<1 + MAXV> ap, is_bad;
int cnt_fact[1 + MAXV];
int main() {
int n;
fin >> n;
int mx = 0;
for (int i = 0; i < n; ++i) {
int x;
fin >> x;
ap[x] = true;
if (x > mx)
mx = x;
}
int64_t ans = 0;
for (int x = 2; x <= mx; ++x)
if (!is_bad[x]) {
int64_t cnt = 0;
bool is_prime = cnt_fact[x] == 0;
for (int y = x; y <= mx; y += x) {
cnt += ap[y];
if (!is_prime)
continue;
++cnt_fact[y];
if (y % (x * x) == 0)
is_bad[y] = true;
}
cnt = (cnt * (cnt - 1)) >> 1;
if (cnt_fact[x] & 1)
ans += cnt;
else ans -= cnt;
}
fout << (int64_t)n * (n - 1) / 2 - ans << '\n';
fin.close();
fout.close();
return 0;
}