Pagini recente » Cod sursa (job #2132803) | Cod sursa (job #2216822) | Cod sursa (job #679216) | Cod sursa (job #2917457) | Cod sursa (job #2145713)
#include <cstdio>
const int MAXN = 1e6;
int cnt[MAXN + 1];
bool pr[MAXN + 1], ok[MAXN + 1], a[MAXN + 1];
int main() {
int n, x, max;
long long ans;
FILE *f = fopen("pairs.in", "r");
fscanf(f, "%d", &n);
max = -1;
for (int i = 0; i < n; ++i) {
fscanf(f, "%d", &x);
a[x] = 1;
if (max < x) {
max = x;
}
}
fclose(f);
for (int i = 2; i <= max; ++i) {
if (!pr[i]) {
for (int j = i; j <= max; j += i) {
pr[j] = 1;
++cnt[j];
if (!(j % (i * i))) {
ok[j] = 1;
}
}
}
}
ans = 0;
for (int i = 2; i <= max; ++i) {
if (!ok[i]) {
x = 0;
for (int j = i; j <= max; j += i) {
x += a[j];
}
if (cnt[i] & 1) {
ans += ((1LL * x * (x - 1)) >> 1);
} else {
ans -= ((1LL * x * (x - 1)) >> 1);
}
}
}
f = fopen("pairs.out", "w");
fprintf(f, "%lld\n", ((1LL * n * (n - 1)) >> 1) - ans);
fclose(f);
return 0;
}