Advertisement
XuanHong

LTTS - tìm x max: n! % 2^x == 0

Feb 2nd, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1.  
  2. // LTTS - tìm x max sao cho n! % 2^x == 0, input n
  3.  
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int n;
  8.  
  9. void main()
  10. {
  11.     cin>>n;
  12.     int sodu=0;
  13.     int dem=0;
  14.     for(int i=2; i<=n; i+=2)
  15.     {
  16.         int tam =i;
  17.         while(tam > 0 && tam % 2 == 0)
  18.         {
  19.             sodu=tam%2;
  20.             tam=tam/2;
  21.             if(sodu==0)            
  22.                 dem++; 
  23.         }
  24.     }
  25.     cout<<dem<<endl;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement