Pagini recente » Cod sursa (job #399801) | Cod sursa (job #186905) | Cod sursa (job #2599468) | Cod sursa (job #2965118) | Cod sursa (job #2521426)
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
ifstream fin("pairs.in");
ofstream fout("pairs.out");
long long ans;
int f[1000001],n,x,aux,d,factori[101],lgfact,nr;
int main()
{
ios_base::sync_with_stdio(false);
fin.tie(0);
fout.tie(0);
fin>>n;
for(int i=1;i<=n;i++)
{
fin>>x;
lgfact=0;
d=2;
while(x!=1)
{
if(x%d==0)
{
factori[++lgfact]=d;
while(x%d==0)
x/=d;
}
d++;
if(d%2==0)
d++;
if(d*d>x&&x>1)
{
factori[++lgfact]=x;
break;
}
}
nr=0;
for(int j=1;j<(1<<lgfact);j++)
{
int a=1;
int x=1;
for(int l=0;l<lgfact;l++)
if((j>>l)&1)
{
a=a*factori[l+1];
x*=-1;
}
nr=nr+f[a]*x;
f[a]++;
}
ans+=i-1+nr;
}
fout<<ans;
return 0;
}