Advertisement
amine99

Untitled

Jun 3rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  5. #define ALL(x) x.begin(),x.end()
  6. #define SZ(x) x.size()
  7. #define PB push_back
  8. #define MP make_pair
  9. #define F first
  10. #define S second
  11. typedef long long LL;
  12. typedef vector<int> VI;
  13. typedef pair<int,int> PI;
  14.  
  15. int t,n;
  16.  
  17. void solve() {
  18.     cin >> n;
  19.     bitset<32> a = n;
  20.     bitset<32> b = n-1;
  21.     string s1 = a.to_string();
  22.     string s2 = b.to_string();
  23.     int ans = 0;
  24.     for(int i = 0; i < 32; i++)
  25.         if(s1[i] != s2[i]) ans++;
  26.     cout << ans << "\n";
  27. }
  28.  
  29. int main() {
  30.     io
  31.     cin >> t;
  32.     while(t--)
  33.         solve();
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement