Pagini recente » Cod sursa (job #395896) | Cod sursa (job #1732873) | Cod sursa (job #473289) | Cod sursa (job #1540272) | Cod sursa (job #183015)
Cod sursa(job #183015)
#include<stdio.h>
#include<math.h>
//lgput(int a,int b){
//}
//int ad(int A,int B){
//}
//int sc(int A,int B){
//}
long long res,A,B;
int ok2,l,p,P[1003],nrf,aux,ok,d,m,n,i,v[1003],max,j,a[1003];
char ap[1001],t[1006];
int main(){
FILE *f=fopen("indep.in","r");
fscanf(f,"%d",&n);
for(i=1;i<=n;i++){
fscanf(f,"%d",&v[i]);
if(v[i]>max)
max=v[i];
ap[v[i]]=1;
}
fclose(f);
for(i=1;i<=max;i++)
for(j=i;j<=max;j+=i)
if(ap[j])
a[i]++;
for(i=2;i<=max;i++){
if(!t[i])
for(j=i+i;j<=max;j+=i)
t[j]=1;
}
p=0;
for(i=2;i<=max;i++)
if(!t[i]){
p++;
P[p]=i;
}
for(i=1;i<=max;i++){
if(a[i]>1){
nrf=0;
aux=i;
ok=1;
d=1;
m=0;
while(aux!=1&&d<=p){
ok2=1;
m=0;
while(!(aux%P[d])){
if(ok2)
nrf++;
m++;
aux/=P[d];
}
if(m>1){
ok=0;
break;
}
d++;
}
if(ok){
if(aux>1)
nrf++;
if(nrf%2==1){
A=1;
for(l=1;l<=a[i];l++)
A*=2;
A--;
A-=a[i];
res-=A;
}
else{
A=1;
for(l=1;l<=a[i];l++)
A*=2;
A--;
A-=a[i];
res+=A;
}
}
}
}
FILE *g=fopen("indep.out","w");
fprintf(g,"%lld",res);
fclose(g);
return 0;
}