Pagini recente » Cod sursa (job #2752641) | Cod sursa (job #2463784) | Cod sursa (job #2961040) | Monitorul de evaluare | Cod sursa (job #3219078)
#include <fstream>
#include <cmath>
using namespace std;
int i,j,t,x,d,maxim,np,aux,ok;
int ap[1000002];
int prim[1010];
char p[1000002];
int a[1000002];
int nr[100002];
long long n, res;
int main(){
ifstream fin ("pairs.in");
ofstream fout("pairs.out");
fin>>n;
for (i=1; i<=n; i++){
fin>>nr[i];
if (nr[i]>maxim)
maxim=nr[i];
ap[nr[i]]=1;
}
for (i=2; i<=maxim; i++)
for (j=i; j<=maxim; j+=i)
if (ap[j])
a[i]++;
for (i=2; i<=maxim/i; i++)
if (p[i]==0)
for (j=i+i; j<=maxim/j; j+=i)
p[j]=1;
np=0;
for (i=2; i<=maxim/i; i++)
if (p[i]==0)
prim[++np]=i;
res=0;
for (i=2; i<=maxim; i++)
if (a[i]>1){
aux = i;
d=1;
x=0;
ok=1;
while (aux!=1){
t=0;
while (aux%prim[d]==0){
aux/=prim[d];
t++;
}
if (t>1){
ok=0;
break;
}
if (t==1)
x++;
d++;
if (d>np) break;
}
if (ok&&(aux!=1))
x++;
if (ok){
if (x%2==1)
res+=(((long long)a[i])*(a[i]-1)/2);
else
res-=(((long long)a[i])*(a[i]-1)/2);
}
}
fout<<n*(n-1)/2-res;
return 0;
}