POPCOUNT
Time limit1sMemory limit1024 MB
Given N, A, and B, the task is to sum f(i) for i from 1 to N, where f(i) is the maximum of A times popcount(a) plus B times popcount(b) over all splits a+b=i.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Bit manipulation, Math
- Solved
- No attempts yet
Problem
For a nonnegative integer , is the number of 1s in the binary representation of .
For positive integers , , and , define as follows.
( and are nonnegative integers)
Given an integer , find the value of .
Input
The first line contains the number of test cases . ()
Each of the next lines contains a test case, given as three positive integers , , and separated by spaces. ()
Output
For each test case, print the answer on its own line. The answer does not exceed the range of a 64-bit integer.