kostes

Untitled

Oct 16th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef unsigned long long ull;
  5. int main()
  6. {
  7. ull n;
  8. cin>>n;
  9. if(n==0)
  10. {
  11. cout<<0;
  12. return 0;
  13. }
  14. int cnt = 0;
  15. while(n!=0)
  16. {
  17. n = n&(n-1);
  18. cnt++;
  19. }
  20. ull k = 0;
  21. for(int i=0;i<cnt-1;i++)
  22. {
  23. k |= 1;
  24. k<<=1;
  25. }
  26. k |= 1;
  27. cout<<k;
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment