Cod sursa(job #475370)

Utilizator Bogdan_CCebere Bogdan Bogdan_C Data 6 august 2010 20:32:56
Problema Pairs Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#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);
    }