题意:给你一个序列,问你有多少个子序列的 gcd=1 g c d = 1
考虑到 m=max{ai} m = m a x { a i } 不是很大,我们可以这样做
gi g i 表示 i i 的个数
表示 i i 的倍数的个数
si s i 表示 i|gcd i | g c d 的子序列个数,显然 si=2fi−1 s i = 2 f i − 1
ansi a n s i 表示 gcd=i g c d = i 的子序列个数 ⇒ansi=∑i|jμ(ji)∗s(j)=si−∑i|jansj ⇒ a n s i = ∑ i | j μ ( j i ) ∗ s ( j ) = s i − ∑ i | j a n s j
这样我们就可以通过枚举倍数在 O(mlogm) O ( m log m ) 的时间里完成这道题了
#include<bits/stdc++.h>
#define fp(i,a,b) for(register int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(register int i=a,I=b-1;i>I;--i)
#define go(u) for(register int i=fi[u],v=e[i].to;i;v=e[i=e[i].nx].to)
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
char ss[1<<17],*A=ss,*B=ss;
inline char gc(){return A==B&&(B=(A=ss)+fread(ss,1,1<<17,stdin),A==B)?-1:*A++;}
template<class T>inline void sd(T&x){
char c;T y=1;while(c=gc(),(c<48||57<c)&&c!=-1)if(c==45)y=-1;x=c-48;
while(c=gc(),47<c&&c<58)x=x*10+c-48;x*=y;
}
char sr[1<<21],z[20];int C=-1,Z;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
template<class T>inline void we(T x){
if(C>1<<20)Ot();if(x<0)sr[++C]=45,x=-x;
while(z[++Z]=x%10+48,x/=10);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=1e5+5,P=1e9+7;
typedef int arr[N];
int n,m;arr f,Mi,ans;
inline int add(int a,int b){return a+=b,a>=P?a-P:a;}
inline int sub(int a,int b){return a-=b,a<0?a+P:a;}
int main(){
#ifndef ONLINE_JUDGE
file("s");
#endif
sd(n);int x;Mi[0]=1;
fp(i,1,n)sd(x),cmax(m,x),++f[x],Mi[i]=add(Mi[i-1],Mi[i-1]);
fp(i,1,m/2)for(int j=2*i;j<=m;j+=i)f[i]+=f[j];
fd(i,m,1){
ans[i]=Mi[f[i]]-1;
for(int j=2*i;j<=m;j+=i)
ans[i]=sub(ans[i],ans[j]);
}we(ans[1]);
return Ot(),0;
}