# yzoj2057 x 题解

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7,MAX=1e6+10;
int T;
long long ans,n,a[MAX],v[MAX],p[MAX],fa[MAX],cnt=0,maxn=-1,book[MAX],sum;
void prime(){
for(int i=2;i<=MAX;++i){
if(!v[i]){
p[++cnt]=i;
for(int j=i;j<=MAX/i;++j) v[i*j]=1;
}
}
}
long long find(long long x){
if(fa[x]==x) return x;
return fa[x]=find(fa[x]);
}
long long clu(long long x,long long y){
long long tmp=1;
while(y){
if(y&1) tmp=(tmp*x)%mod;
x=(x*x)%mod;
y=y>>1;
}
return tmp%mod;
}
int main(){
prime();
scanf("%d",&T);
while(T--){
scanf("%lld",&n);
memset(a,0,sizeof(a));
memset(book,0,sizeof(book));
memset(v,0,sizeof(v));
ans=0,maxn=-1,sum=0;
for(int i=1;i<=MAX;++i) fa[i]=i;
for(int i=1;i<=n;++i){
scanf("%lld",&a[i]);
maxn=max(maxn,a[i]);
if(a[i]==1) sum++;
v[a[i]]++;
}
for(int i=1;i<=cnt;++i){
for(int j=1;j*p[i]<=maxn;++j){
if(v[j*p[i]]){
long long fax=find(p[i]);
long long fbx=find(j*p[i]);
if(fax!=fbx) fa[fax]=fbx;
}
}
}
for(int i=1;i<=n;++i){
if(!book[find(a[i])]) ans++,book[find(a[i])]=1;
}
if(sum>1) ans+=(sum-1);
ans=clu(2,ans);
ans=(ans-2+mod)%mod;
printf("%d\n",ans);
}
return 0;
}

posted @ 2019-08-26 20:38  End_donkey  阅读(152)  评论(0编辑  收藏  举报