Saleh127

UVA 12888 / Mobious Function

Feb 8th, 2022
1,105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. /***
  2.  created: 2022-02-08-22.35.22
  3. ***/
  4.  
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. #define ll long long
  8. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  9. #define get_lost_idiot return 0
  10. #define nl '\n'
  11.  
  12. ll mob[1000005];
  13. bitset<1000005>marked;
  14.  
  15. void mobious()
  16. {
  17.      ll i,j,k,l;
  18.  
  19.      for(i=0;i<1000002;i++)
  20.      {
  21.           mob[i]=1;
  22.      }
  23.  
  24.      for(i=2;i<1000002;i++)
  25.      {
  26.           if(marked[i]==0)
  27.           {
  28.                mob[i]*=-1;
  29.  
  30.                for(j=i+i;j<1000002;j+=i)
  31.                {
  32.                     marked[j]=1;
  33.  
  34.                     if(j%(i*i)==0) mob[j]=0;
  35.                     else mob[j]*=-1;
  36.                }
  37.           }
  38.      }
  39. }
  40.  
  41.  
  42. int main()
  43. {
  44.    ios_base::sync_with_stdio(0);
  45.    cin.tie(0);cout.tie(0);
  46.  
  47.    mobious();
  48.  
  49.    test
  50.    {
  51.         ll n,m,i,j,k,l;
  52.  
  53.         cin>>n>>m;
  54.  
  55.         if(n>m) swap(n,m);
  56.  
  57.         l=n*m;
  58.  
  59.         for(i=2;i<=n;i++)
  60.         {
  61.              l+=mob[i]*(n/i)*(m/i);
  62.         }
  63.         cout<<l<<nl;
  64.    }
  65.  
  66.  
  67.  
  68.    get_lost_idiot;
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment