Pagini recente » Cod sursa (job #2040860) | Simulare 04 | Cod sursa (job #2830432) | Cod sursa (job #1917385) | Cod sursa (job #2479131)
#include <cstdio>
using namespace std;
const int S = 1 << 17;
char buf[S];
int ptr = S;
char urm()
{
if (ptr == S)
{
fread(buf, 1, S, stdin);
ptr = 0;
}
return buf[ptr++];
}
int read()
{
int ans = 0;
char c = urm();
while (c < '0' || '9' < c)
c = urm();
while ('0' <= c && c <= '9')
{
ans = 10 * ans + c - '0';
c = urm();
}
return ans;
}
const int N = 1000000 + 7;
int n, cnt[N], mx;
long long sol[N];
int main()
{
freopen ("pairs.in", "r", stdin);
freopen ("pairs.out", "w", stdout);
n = read();
while (n--)
{
int x = read();
cnt[x]++;
if (x > mx)
mx = x;
}
for (int i = 1; i <= mx; i++)
for (int j = 2 * i; j <= mx; j += i)
cnt[i] += cnt[j];
for (int i = mx; i >= 1; i--)
if (cnt[i])
{
sol[i] = cnt[i] * (long long) (cnt[i] - 1) / 2;
for (int j = 2 * i; j < N; j += i)
sol[i] -= sol[j];
}
printf("%lld\n", sol[1]);
return 0;
}