Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef unsigned long long ull;
- int main()
- {
- ull n;
- cin>>n;
- if(n==0)
- {
- cout<<0;
- return 0;
- }
- int cnt = 0;
- while(n!=0)
- {
- n = n&(n-1);
- cnt++;
- }
- ull k = 0;
- for(int i=0;i<cnt-1;i++)
- {
- k |= 1;
- k<<=1;
- }
- k |= 1;
- cout<<k;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment