Pagini recente » Cod sursa (job #2117457) | Borderou de evaluare (job #2907029) | Cod sursa (job #59201) | Cod sursa (job #1399017) | Cod sursa (job #2737507)
#include <bits/stdc++.h>
namespace FastRead {
const int Dim(1e6);
char buff[Dim];
int pos, len;
inline char nc() {
if (pos == len) {
pos = 0;
len = fread(buff, 1, Dim, stdin);
if (!len) return EOF;
}
return buff[pos++];
}
template<class T> inline void Read(T& x) {
char ch;
int sgn(1);
while (!isdigit(ch = nc()))
if (ch == '-')
sgn = -1;
x = ch - '0';
while (isdigit(ch = nc()))
x = x * 10 + (ch - '0');
x *= sgn;
}
}
using namespace FastRead;
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], prim;
i64 res, curr;
signed main() {
DAU("pairs");
Read(n);
for (int i = 1; i <= n; ++i) {
Read(x);
freq[x] = 1;
maxi = max(maxi, x);
}
for (int i = 2; i <= maxi; ++i)
if (!no[i]) {
curr = 0;
prim = (!nrf[i]);
for (int j = i; j <= maxi; j += i) {
curr += freq[j];
if (!prim)
continue;
++nrf[j];
if (j % (i * i) == 0)
no[j] = true;
}
curr = curr * (curr - 1) / 2;
if (nrf[i] & 1)
res += curr;
else res -= curr;
}
res = 1LL * n * (n - 1) / 2 - res;
cout << res;
PLEC();
}