Pagini recente » Cod sursa (job #555927) | Cod sursa (job #321095) | Cod sursa (job #3183930) | Cod sursa (job #2342806) | Cod sursa (job #2737497)
#include <bits/stdc++.h>
using namespace std;
void DAU(const string& task = "") {
if (!task.empty())
freopen((task + ".in").c_str(), "r", stdin),
freopen((task + ".out").c_str(), "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
void PLEC() {
exit(0);
}
using i64 = long long;
const int N(1000005);
int n, x, maxi, nrf[N];
bool freq[N], no[N];
i64 res, curr;
signed main() {
DAU("pairs");
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> x;
freq[x] = 1;
maxi = max(maxi, x);
}
for (int i = 2; i <= maxi; ++i)
if (!no[i]) {
curr = 0;
for (int j = i; j <= maxi; j += i) {
curr += freq[j];
nrf[j] += (!nrf[i]);
if (j % (i * i) == 0)
no[j] = true;
}
curr = curr * (curr - 1) / 2;
if (nrf[i] & 1)
res += curr;
else res -= curr;
}
cout << res;
PLEC();
}