![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <bitset> 6 #include <vector> 7 #include <queue> 8 #include <stack> 9 #include <cmath> 10 #include <list> 11 #include <set> 12 #include <map> 13 #define rep(i,a,b) for(int i = a;i <= b;++ i) 14 #define per(i,a,b) for(int i = a;i >= b;-- i) 15 #define mem(a,b) memset((a),(b),sizeof((a))) 16 #define FIN freopen("in.txt","r",stdin) 17 #define FOUT freopen("out.txt","w",stdout) 18 #define IO ios_base::sync_with_stdio(0),cin.tie(0) 19 #define mid ((l+r)>>1) 20 #define ls (id<<1) 21 #define rs ((id<<1)|1) 22 #define INF 0x3f3f3f3f 23 using namespace std; 24 typedef long long LL; 25 typedef pair<int, int> PIR; 26 const int N = 1e5+5; 27 28 LL n; 29 int main() 30 {IO; 31 // FIN; 32 // FOUT; 33 while(cin >> n){ 34 LL ans = 0; 35 while(n){ 36 if(n&1) ans += (1+n)*(n/2+1)/2; 37 else ans += n*(n/2)/2; 38 n >>= 1; 39 } 40 cout << ans << endl; 41 } 42 return 0; 43 }