标签:blog io ar os for sp div on 2014
#include<iostream> #include<vector> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define LL __int64 const int maxn = 1e5+8; LL a[maxn],cn,numpri[maxn],vis[maxn],dis[maxn]; LL n,m; LL f[maxn]; void getprim(){ cn = 0; for(LL i=2;i<1000;i++){ if(!dis[i]){ numpri[cn++] = i; for(LL j=2*i;j<=1000;j+=i) dis[j] = 1; } } } LL getans(){ vector <int > v; LL ans1 = 0; for(LL i=0;i<n;i++){ v.clear(); LL d = a[i],sum = 0;; for(LL j=0;j<cn&&numpri[j] * numpri[j] <=d;j++){ if(d % numpri[j] == 0){ v.push_back(numpri[j]); while(d % numpri[j] == 0)d /= numpri[j]; } } if(d!=1)v.push_back(d); int len = v.size(); //cout << len <<endl; for(int j=0;j<(1<<len);j++){ LL op =0,ans = 1; for(int k=0;k<len;k++){ if((1<<k)&j){ op++; ans*=v[k]; } } if(op&1)sum+=f[ans]; else sum -= f[ans]; } if(sum <= 0) continue; ans1 += (sum - 1) *(n-sum); } return ans1 /2; } int main(){ LL T; scanf("%I64d",&T); getprim(); while(T--){ memset(f,0,sizeof(f)); memset(vis,0,sizeof(vis)); scanf("%I64d",&n); for(LL i=0;i<n;i++){ scanf("%I64d",&a[i]); vis[a[i]] = 1; } for(int i=2;i<maxn;i++){ for(int j=i;j<maxn;j+=i){ if(vis[j])f[i]++; } } LL ans = n*(n-1)*(n-2)/6; ans -= getans(); cout << ans<<endl; } }
标签:blog io ar os for sp div on 2014
原文地址:http://blog.csdn.net/wyl_zheyang/article/details/40831459