Pagini recente » Cod sursa (job #297180) | Cod sursa (job #2762007) | Cod sursa (job #2923270) | Cod sursa (job #507272) | Cod sursa (job #475369)
Cod sursa(job #475369)
#include<stdio.h>
#define FIN "pairs.in"
#define FOUT "pairs.out"
#define NMAX 100001
int N,A[NMAX] , C[NMAX] , V[NMAX] , DIV[NMAX] , nu[NMAX];
char PRIM[NMAX];
long long REZ = 0;
int main()
{
freopen(FIN , "r" , stdin);
freopen(FOUT , "w" , stdout);
scanf("%d" , &N);
for(int i = 0 ; i < N ; ++i)
{
scanf("%d",&A[i]);
C[A[i]] = 1;
}
for(int i = 2 ; i < NMAX ; ++i)
{
for(int j = 2 * i ; j < NMAX ; j += i)
C[i] += C[j];
if(!PRIM[i])
{
DIV[i] = 1;
for(int j = 2*i ; j < NMAX ; j += i)
{
PRIM[j] = 1;
DIV[j] ++;
}
}
if(DIV[i] % 2 == 0)
REZ -= 1LL * C[i] * (C[i] - 1) / 2;
else
REZ += 1LL * C[i] * (C[i] - 1) / 2;
}
printf("%lld" , 1LL * N * (N - 1) / 2 - REZ);
}