Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- using namespace std;
- int main(){
- int t;
- cin >> t;
- while (t>0){t--;
- int n;
- string bin="";
- cin>>n;
- int ones=0;
- if(n==0)cout << 0;
- else{
- for(int i=n; i>0; i/=2){
- int a=i%2;
- if(a==1)ones++;
- bin=to_string(a)+bin;
- }
- cout<< pow(2,ones)-1<< endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment