Cod sursa(job #1752260)

Utilizator Bodo171Bogdan Pop Bodo171 Data 3 septembrie 2016 13:10:08
Problema Pairs Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <iostream>
#include<fstream>
#include<bitset>
using namespace std;
const int nmax=1000000;
bitset<nmax+10> ap;
int x,n,i,j,grd[nmax+10];
long long ad,tot,c;
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<=nmax;i++)
    {
     if(grd[i]==0)
        for(j=i;j<=nmax;j+=i)
      {
        grd[j]++;
      }
      if(grd[i]%2==0) ad=-1;
      else ad=1;
      c=0;
      for(j=i;j<=nmax;j+=i)
      {
          if(ap[j]) c++;
      }
      tot+=c*(c-1)*ad;
    }
    tot=n*(n-1)-tot;
    tot/=2;
    g<<tot;
    return 0;
}