Under construction

Still being built. Things may change

Bit Count (Small)

Time limit5sMemory limit512 MB

Summary
Given N, split it into nonnegative a and b with a plus b equal to N to maximize the total count of 1 bits in a and b.
Level

Medium5 of 10

Topics
Bit manipulation, Dynamic programming
Solved
No attempts yet

Problem

Let f(x)f(x) be the function that returns the number of ones in the binary representation of xx. For example, 5 is written as 101(2)101_{(2)} in binary, so f(5)=2f(5) = 2.

You are given a positive integer NN. Among all pairs of integers a,b≥0a, b \ge 0 with a+b=Na + b = N, find a pair that maximizes f(a)+f(b)f(a) + f(b) and print that maximum value.

Input

The first line contains the number of test cases TT. Each of the next TT lines contains one positive integer NN.

Constraints

  • 1≤T≤10001 \le T \le 1000
  • 1≤N≤10181 \le N \le 10^{18}

Output

For each test case, print one line in the following form.

Case #X: P

Here XX is the test case number starting from 1, and PP is the maximum value of f(a)+f(b)f(a) + f(b).

Examples1

  1. Example 1

    Input
    4
    1
    4
    31
    1125899906842624
    
    Expected output
    Case #1: 1
    Case #2: 3
    Case #3: 5
    Case #4: 51