Advertisement
tvermaashutosh

UNCHANGEDOR CodeChef Starters 31 Problem:

Jun 24th, 2022
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define B(x) (1<<x)
  4. #define ll long long
  5. int main() {
  6.  
  7.     int t;
  8.     cin>>t;
  9.     while(t--) {
  10.         int n;
  11.         cin>>n;
  12.  
  13.         int p, temp=0;
  14.         for(p=0; ; p++) if(n < B(p)) break;
  15.         p--;
  16.        
  17.         for( int i=B(0), j=0; i<=B(p); i=i+B(++j) ) temp += B(j) -1;
  18.  
  19.  
  20.         temp += n - B(p);
  21.  
  22.  
  23.         cout<<temp<<endl;
  24.        
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement