Pagini recente » Cod sursa (job #3037528) | Cod sursa (job #2384123) | Cod sursa (job #2290738) | Cod sursa (job #3164056) | Cod sursa (job #3290993)
#include <fstream>
#include <vector>
#define int long long
#define nmax (int)(1e5+5)
#define dim (int)(1e6+5)
using namespace std;
ifstream cin("pairs.in");
ofstream cout("pairs.out");
int n,sol,x,maxi,nr[dim];
bool mobius[dim];
vector<int>p;
signed main()
{
cin>>n;
for(int i=1;i<=n;i++){
cin>>x;
for(int d=1;d*d<=x;d++)
if(x%d==0){
nr[d]++;
if(x/d!=d)
nr[x/d]++;
}
maxi=max(maxi,x);
}
for(int i=2;i<=maxi;i++){
int t=0,x=i;
for(int d=2;d*d<=x;d++)
if(x%d==0){
if(x/d%d==0){
x=0;
break;
}
x/=d;
t++;
}
if(x==0)
continue;
if(x!=1)
t++;
if(t%2==0)
mobius[i]=-1;
else
mobius[i]=1;
}
for(int i=2;i<=maxi;i++)
if(nr[i]>1)
sol+=nr[i]*(nr[i]-1)/2*mobius[i];
cout<<n*(n-1)/2-sol;
return 0;
}