Pagini recente » Cod sursa (job #1860455) | Cod sursa (job #1009185) | Cod sursa (job #13307) | Cod sursa (job #679475) | Cod sursa (job #1960854)
#include <bits/stdc++.h>
#define DIM 1000010
using namespace std;
int ap[DIM],n,x,pr[DIM],nr;
bool ok[DIM];
long long ans,j,i;
int main()
{
ifstream f ("pairs.in");
ofstream g ("pairs.out");
f>>n;
for(i=1; i<=n; ++i)
{
f>>x;
ap[x]=1;
}
for(i=2; i<=DIM; ++i)
if(!pr[i])
{
for(j=i; j<DIM; j+=i)
pr[j]++;
for(j=i*i; j<DIM; j+=i*i)
ok[j]=true;
}
for(i=1; i<=DIM; ++i)
if(!ok[i])
{
nr=0;
for(j=i; j<DIM; j+=i)
nr+=ap[j];
if(!pr[i]%2)ans+=(nr)*(nr-1)/2;
else ans-=nr*(nr-1)/2;
}
g<<ans;
return 0;
}