当前位置:网站首页>Educational Codeforces Round 20 F. Coprime Subsequences

Educational Codeforces Round 20 F. Coprime Subsequences

2022-06-09 05:55:00 不吃土司边

#include<bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define eps 1e-2
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;

const int maxn = 1e5+2;
const int maxm=1e5;
const int INF  = 1<<30;
const int mod  = 1e9+7;
#define int long long 

int n,a[maxn],cnt[maxn];
int dp[maxn],p[maxn];


void solve(){
    
    p[0]=1;for(int i=1;i<maxn;i++) p[i]=p[i-1]*2,p[i]%=mod;
    scanf("%lld",&n);for(int i=1;i<=n;i++) scanf("%lld",&a[i]),cnt[a[i]]++;
    for(int i=maxn;i>=1;i--){
    
        for(int j=1;j*i<=maxm;j++){
    
            dp[i]=(dp[i]+cnt[i*j])%mod;
        }
        dp[i]=p[dp[i]]-1;
        for(int j=2;j*i<=maxm;j++){
    
            dp[i]=(dp[i]-dp[i*j]+mod)%mod;
        }
        // cout<<dp[i]<<endl;
    }    
    cout<<dp[1]<<endl;
    return;
        
}

int32_t main()
{
    
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// ios::sync_with_stdio(false);
    int t = 1;
    //scanf("%d",&t);
    while(t--){
    
    // printf("Case %d: ",cas++);
        solve();
    }
    return 0;
}
原网站

版权声明
本文为[不吃土司边]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_45714303/article/details/125070479