Pagini recente » Cod sursa (job #2737718) | Cod sursa (job #2572524) | Cod sursa (job #2955950) | Cod sursa (job #2237566) | Cod sursa (job #2520367)
#include <bits/stdc++.h>
#define VALUEMAX 1000005
using namespace std;
ifstream f ("pairs.in");
ofstream g ("pairs.out");
long long n;
int x;
int fr[VALUEMAX] , nrdiv[VALUEMAX];
bool a[VALUEMAX];
int main()
{
long long i = 0 , j = 0;
int xmax = 0;
f >> n;
long long ans = n * (n - 1) / 2 , cnt = 0;
for(i = 1 ; i <= n ; i++)
{
f >> x;
++fr[x];
xmax = max(xmax , x);
}
for(i = 2 ; i <= xmax ; i++)
{
if(nrdiv[i] == 0)
{
for(j = i ; j <= xmax ; j += i)
{
++nrdiv[j];
if(j % (i * i) == 0)
a[j] = 1;
}
}
if(a[i] == 0)
{
cnt = 0;
for(j = i ; j <= xmax ; j += i)
cnt += fr[j];
if(nrdiv[i] % 2 == 1)
ans -= cnt * (cnt - 1) / 2;
else ans += cnt * (cnt - 1) / 2;
}
}
g << ans;
return 0;
}