Pagini recente » Cod sursa (job #1426665) | Cod sursa (job #2688386) | Cod sursa (job #2400810) | Cod sursa (job #2104661) | Cod sursa (job #2295401)
# include <fstream>
# define DIM 1000010
using namespace std;
ifstream fin("pairs.in");
ofstream fout("pairs.out");
int d[DIM],f[DIM],nr[DIM],n,x,i,j,val;
long long sol;
int main () {
fin>>n;
for(i=1;i<=n;i++){
fin>>x;
f[x]=1;
}
for(i=1;i<=DIM-5;i++)
d[i]=1;
for(i=1;i<=DIM-5;i++){
if(d[i]==i||d[i]==1){
val=0;
for(j=i;j<=DIM-5;j+=i){
d[j]*=i;
nr[j]++;
if(f[j])
val++;
}
if(nr[i]%2==1)
sol+=(1LL*val*(val-1))/2;
else
sol-=(1LL*val*(val-1))/2;
}
}
fout<<sol<<"\n";
return 0;
}