Pagini recente » Cod sursa (job #2923270) | Cod sursa (job #507272) | Cod sursa (job #475369) | Cod sursa (job #2421455) | Cod sursa (job #475370)
Cod sursa(job #475370)
#include<stdio.h>
#define FIN "pairs.in"
#define FOUT "pairs.out"
#define NMAX 100001
#define MMAX 1000002
int N,A[NMAX] , C[MMAX] , V[MMAX] , DIV[MMAX] , nu[NMAX];
char PRIM[MMAX];
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 < MMAX ; ++i)
{
for(int j = 2 * i ; j < MMAX ; 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);
}