Cod sursa(job #3257183)

Utilizator Rares0netOnet Rares-Petru Rares0net Data 16 noiembrie 2024 20:56:50
Problema Pairs Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
//Rares 0net

//Principiul incluziunii si excluziunii
using namespace std;
using LL=long long int;
#ifdef RS
#include<d:\\Rares0.hpp>
#else
#include<limits>
#include<fstream>
const string N_file="pairs";
ifstream fin(N_file+".in");
ofstream fout(N_file+".out");
#define cin fin
#define cout fout
#endif
#define endl '\n'
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define f first
#define s second
#define INF 0x3f3f3f
void RSinit()
{
    cin.tie(0)->sync_with_stdio(false);
    cout.tie(0);
}
const int nMAX=1e6;
LL fr[nMAX+1];
LL Ans[nMAX+1];
int n;
int mx=numeric_limits<int>::min();
void Read()
{
    cin>>n;
    for(int i=1; i<=n; ++i)
    {
        int x;
        cin>>x;
        ++fr[x];
        mx=max(mx, x);
    }
}
void Solve()
{
    for(int i=mx; i>=1; --i)
    {
        for(int j=i; j<=mx; j+=i)
            Ans[i]+=fr[j];
        Ans[i]=Ans[i]*(Ans[i]-1)/2;
        for(int j=2*i; j<=mx; j+=i)
            Ans[i]-=Ans[j];
    }
    cout<<Ans[1];
}
main()
{
    RSinit();
    Read();
    Solve();
}