803F - Coprime Subsequences - CodeForces Solution


bitmasks combinatorics number theory *2000

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;

long long m=1e9+7;
vector<long long>v(1e5+5),v2(1e5+5);

long long p(long long n){
if(n==1){return 2;}
long long b=p(n/2);
b*=b;b%=m;
if(n%2){b*=2;}
return b%m;
}

int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int tst=1;//cin>>tst;
while(tst--){
int a;cin>>a;
while(a--){
    int c;cin>>c;
    for(long long d=1;d*d<=c;d++){
        if(c%d==0){v[d]++;if(d!=c/d){v[c/d]++;}}
    }
}
for(int c=1e5;c>=1;c--){
if(v[c]){v2[c]=(p(v[c])-1);
if(v2[c]<0){v2[c]+=m;}
for(int d=c+c;d<=1e5;d+=c){v2[c]-=v2[d];}
if(v2[c]<0){v2[c]+=m;}
v2[c]%=m;
}
}
if(v2[1]<0){v2[1]+=m;}
cout<<v2[1]%m;
}
return 0;
}


Comments

Submit
0 Comments
More Questions

1183B - Equalize Prices
1481A - Space Navigation
1437B - Reverse Binary Strings
1362B - Johnny and His Hobbies
1299A - Anu Has a Function
1111A - Superhero Transformation
954A - Diagonal Walking
39F - Pacifist frogs
1451C - String Equality
386A - Second-Price Auction
1690E - Price Maximization
282B - Painting Eggs
440A - Forgotten Episode
233B - Non-square Equation
628B - New Skateboard
262B - Roma and Changing Signs
755C - PolandBall and Forest
456B - Fedya and Maths
376B - IOU
1623B - Game on Ranges
1118A - Water Buying
1462C - Unique Number
301A - Yaroslav and Sequence
38A - Army
38C - Blinds
1197A - DIY Wooden Ladder
1717D - Madoka and The Corruption Scheme
1296D - Fight with Monsters
729D - Sea Battle
788A - Functions again