Bit Count (Small)
Time limit5sMemory limit512 MB
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 be the function that returns the number of ones in the binary representation of . For example, 5 is written as in binary, so .
You are given a positive integer . Among all pairs of integers with , find a pair that maximizes and print that maximum value.
Input
The first line contains the number of test cases . Each of the next lines contains one positive integer .
Constraints
Output
For each test case, print one line in the following form.
Case #X: P
Here is the test case number starting from 1, and is the maximum value of .