Advertisement
RaFiN_

mobious function

Aug 13th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. /* Mobious Function */
  2.  
  3. int miu[MAX],mark[MAX];
  4.  
  5. void mobius(int n){
  6.  for(int i=0;i<=n;i++) miu[i]=1;
  7.        miu[0]=0;
  8.        miu[1]=1;
  9.       for(int i=2;i<=n;i++){
  10.              if(mark[i]) continue;
  11.                 miu[i]=-1;
  12.            for(int j=i*2;j<=n;j+=i){
  13.                if(miu[j]!=0){
  14.                    if(j%(i*i)==0) miu[j]=0;
  15.                    else miu[j]*=-1;
  16.                    mark[j]=1;
  17.                }
  18.            }
  19.     }
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement