Cod sursa(job #3275628)

Utilizator paull122Paul Ion paull122 Data 11 februarie 2025 10:35:05
Problema Pairs Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("pairs.in");
ofstream fout("pairs.out");

#define NMAX 1000000
#define ll long long int
ll cnt[NMAX+1];
int n;

int main()
{
  fin >> n;
  for(int i=1;i<=n;i++)
  {
      int x;
      fin >> x;
      for(int d=1;d*d<=x;d++)
      {
        if(x%d==0)
        {
          cnt[d]++;
          if(d*d!=x)
          {
            cnt[x/d]++;
          }
        }
      }
  }

  for(int i=NMAX;i>=1;i--)
  {
      cnt[i] = cnt[i]*1ll*(cnt[i]-1)/2;
      for(int j=2;j*1ll*i<=NMAX;j++)
      {
         cnt[i] -= cnt[j*i];
      }
  }
  fout << cnt[1];
}