lina_os

Untitled

Nov 2nd, 2024
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. int main(){
  9.  
  10. int t;
  11. cin >> t;
  12. while (t>0){t--;
  13. int n;
  14. string bin="";
  15. cin>>n;
  16. int ones=0;
  17. if(n==0)cout << 0;
  18. else{
  19. for(int i=n; i>0; i/=2){
  20. int a=i%2;
  21. if(a==1)ones++;
  22. bin=to_string(a)+bin;
  23.  
  24. }
  25. cout<< pow(2,ones)-1<< endl;
  26.  
  27. }
  28. }
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment