Advertisement
Saleh127

CF 803F / Mobius Function

Jan 11th, 2023
719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. /***
  2.  created: 2023-01-11-23.19.07
  3. ***/
  4.  
  5. #include <bits/stdc++.h>
  6. #include <ext/pb_ds/assoc_container.hpp>
  7. #include <ext/pb_ds/tree_policy.hpp>
  8. using namespace std;
  9. using namespace __gnu_pbds;
  10. template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
  11. #define ll long long
  12. #define all(we) we.begin(),we.end()
  13. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  14. #define nl '\n'
  15.  
  16. const ll mod=1e9+7;
  17. #define maxN 100007
  18. int mob[maxN];
  19. bool mark[maxN];
  20. void mobius()
  21. {
  22.     ll i, j;
  23.     for(i = 0; i < maxN; i++) mob[i] = 1;
  24.     for(i = 2; i < maxN; i++)
  25.     {
  26.         if(!mark[i])
  27.         {
  28.             mob[i] *= -1;
  29.             for(j = i + i; j < maxN; j += i)
  30.             {
  31.                 mark[j] = true;
  32.                 mob[j] *= j % (i * i) ? -1 : 0;
  33.             }
  34.         }
  35.     }
  36. }
  37.  
  38. ll bigmod(ll a,ll c,ll d)
  39. {
  40.     if(c==0) return 1LL;
  41.     ll x=bigmod(a,c/2,d);
  42.     x=(x*x)%d;
  43.     if(c%2==1LL)
  44.     {
  45.         x=(x*a)%d;
  46.     }
  47.     return x;
  48. }
  49.  
  50. ll c[maxN];
  51.  
  52. int main()
  53. {
  54.     ios_base::sync_with_stdio(0);
  55.     cin.tie(0);
  56.     cout.tie(0);
  57.  
  58.     mobius();
  59.  
  60.     ll n,m,i,j,k,l;
  61.  
  62.     cin>>n;
  63.  
  64.     for(i=0;i<n;i++)
  65.     {
  66.         cin>>m;
  67.         c[m]++;
  68.     }
  69.  
  70.     ll ans=0;
  71.  
  72.     for(i=1;i<maxN;i++)
  73.     {
  74.         k=0;
  75.         for(j=i;j<maxN;j+=i)
  76.         {
  77.             k+=c[j];
  78.         }
  79.  
  80.         ans+=((mob[i]*(bigmod(2,k,mod)-1+mod)%mod)+mod)%mod;
  81.         ans%=mod;
  82.     }
  83.  
  84.     cout<<ans<<nl;
  85.  
  86.     return 0;
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement