#CF2240A. 又一道 Popcount 问题 / A. Another Popcount Problem
又一道 Popcount 问题 / A. Another Popcount Problem
A. Another Popcount Problem
Source: Codeforces 2240A
Contest: Codeforces Round 1105 (Div. 2)
Time limit: 1 second
Memory limit: 256 megabytes
Statement
You are given two integers and .
Your task is to construct a sequence consisting of non-negative integers such that:
- The total number of set bits, i.e., , is as large as possible.
You only need to output the maximum possible value of .
Here, denotes the number of bits in the binary representation of . For example, $\operatorname{popcount}(6) = \operatorname{popcount}((110)_2) = 2$, and .
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
Each of the next lines contains two integers and () — the maximum allowed sum of the sequence and the length of the sequence, respectively.
Output
For each test case, output a single integer — the maximum possible value of .
Note
In the first test case, and . We can choose or . In both cases, the sum of popcounts is .
In the second test case, and . We can choose , since , .
In the third test case, and . We can choose . The sum is , and the total popcount is $\operatorname{popcount}(3) + \operatorname{popcount}(3) = 2 + 2 = 4$.
Examples
6
2 1
3 1
6 2
14142 137205
1000000 100
1000000 1000000
1
2
4
14142
1322
1000000