题解:CF803F Coprime Subsequences(求集合里所有的gcd=x的子序列数量)(很典!)
huangmuye_phi · · 个人记录
1.题意
给定一个序列
2.解析
直接求解当
时间复杂度为
:::info[Code]
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#define int long long
using namespace std;
const int N=1e5+10,MXA=1e5,MOD=1e9+7;
int n,a[N];
int tong[N],po[N],f[N];
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
cin>>n;
po[0]=1;
for(int i=1;i<=n;i++){
po[i]=(po[i-1]*2)%MOD;
cin>>a[i];
tong[a[i]]++;
}
for(int i=MXA;i>=1;i--){
int sum=0;
for(int j=i;j<=MXA;j+=i){
sum+=tong[j];
}
f[i]=po[sum]-1;
for(int j=i*2;j<=MXA;j+=i){
f[i]=((f[i]-f[j])%MOD+MOD)%MOD;
}
}
cout<<f[1];
return 0;
}
:::