/* -*- coding: utf-8 -*- * * 2939.cc: No.2939 Sigma Popcount Problem - yukicoder */ #include #include using namespace std; /* constant */ const int BN = 40; /* typedef */ using ll = long long; /* global variables */ ll dp[BN + 1]; /* subroutines */ /* main */ int main() { dp[0] = 0; for (int i = 0; i < BN; i++) dp[i + 1] = dp[i] * 2 + (1LL << i); //for (int i = 0; i <= 10; i++) printf(" %lld", dp[i]); putchar('\n'); int tn; scanf("%d", &tn); while (tn--) { ll n; scanf("%lld", &n); n++; ll sum = 0; for (int i = BN - 1, c = 0; i >= 0; i--) { int bi = (n >> i) & 1; if (bi) { sum += dp[i] + (1LL << i) * c; c++; } } printf("%lld\n", sum); } return 0; }