Pagini recente » Cod sursa (job #2516940) | Cod sursa (job #1505149) | Cod sursa (job #2261153) | Cod sursa (job #2154183) | Cod sursa (job #1344948)
#include<stdio.h>
#define DIM 1000023
#define LL long long int
FILE *fin, *fout;
bool check[DIM];
LL v[DIM];
LL n,max=0,i,j,sol,x;
int main()
{
fin = freopen("pairs.in","r",stdin);
fout = freopen("pairs.out","w",stdout);
scanf("%lld",&n);
sol=n*(n-1)/2;
for(i=1;i<=n;i++)
{
scanf("%lld",&x);
check[x]=1;
if(x>max)
max=x;
}
for(i=2;i<=max;i++)
if(v[i]==0)
for(j=i;j<=max;j+=i)
++v[j];
for(i=2;i*i<=max;i++)
for(j=i*i;j<=max;j+=i*i)
v[j]=-1;
for(i=2;i<=max;i++)
{
if(v[i]!=-1)
{
x=0;
for(j=i;j<=max;j=j+i)
if(check[j])
++x;
if(v[i]%2) sol -= x*(x-1)/2;
else sol += x*(x-1)/2;
}
}
printf("%lld\n",sol);
fclose(fin);
fclose(fout);
return 0;
}