#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef pair pii; typedef long long ull; typedef long long ll; typedef vector vi; #define xx first #define yy second #define rep(i, a, n) for (int i = a; i < n; i++) #define sa(n) scanf("%d", &(n)) #define vep(c) for(decltype((c).begin()) it = (c).begin(); it != (c).end(); it++) const int mod = int(1e4) + 7, INF = 0x3fffffff, maxn = 1e5 + 12; ll n; ull sum[maxn]; int T; int geti(ll x) { int i = 0; while ((1ll << i) <= x) i++; return i - 1; } void getsum(void) { sum[0] = 0; for (ull i = 1; (1ull << i) <= ull(1e16); i++) { sum[i] = sum[i - 1] + sum[i - 1] + (1ull << i) - (1ull <<(i -1)); } } ull dfs(ll x) { if (x <= 0) return 0; int t = geti(x); return sum[t] + dfs(x - (1ll << t)) + 1 + x - (1ll << t); } int main(void) { cin >> T; getsum(); while (T--) { cin >> n; cout << dfs(n) << endl; } return 0; } /* int n, h, v[2222]; double p; map, double> dp[2222][2222]; int getid(int x) { return lower_bound(v, v + n, x) - v + 1; } double dfs(int l, int r, int lf, int rf) { int li = getid(l), ri = getid(r); if (dp[li][ri].count(make_pair(lf, rf))) return dp[li][ri][make_pair(lf, rf)]; if (l > r) return 0; double ret = 0.0; //左边的树倒 ret += p * 0.5 * (min(h, v[l] - lf) + dfs(l + 1, r, v[l], rf)); int x = l + 1; while (v[x] < v[x - 1] + h && x <= r) x++; x--; ret += (1 - p) * 0.5 * (min(v[x] - v[l] + h, rf - v[l]) + dfs(x + 1, r, v[x] + h, rf)); //右边的树倒 ret += (1 - p) * 0.5 * (min(h, rf - v[r]) + dfs(l, r - 1, lf, v[r])); x = r - 1; while (v[x] > v[x - 1] - h && x >= l) x--; x++; ret += p * 0.5 * (min(v[r] - v[x] + h, v[r] - lf) + dfs(l, x - 1, lf, v[x] - h)); return dp[li][ri][make_pair(lf, rf)] = ret; } int main(void) { sa(n), sa(h); scanf("%lf", &p); rep (i, 0, n) sa(v[i]); sort(v, v + n); printf("%.15f\n", dfs(0, n - 1, -INF, INF)); return 0; }*/