Funny Bits


Funny Bits

Problem Statement

Let aa be the average (rounded down) of all positive integers up to kk-bits with nn bits set.

(A bit is "set" if it equals one. For example, in the binary number 1101, there is a total of 3 bits set.)

Given kk and aa, find nn.

Input

Your only line of input will contain two space-separated integers, kk and aa.

Output

One line, containing only the number nn.

Constraints

For all test cases:

  • 1≤k≤301 \le k \le 30
  • 1≤a≤10101 \le a \le 10^{10}
  • There will always be a unique valid nn for the given kk and aa.

Sample Test Cases

Example 1
Input 1
4 7
Output 1
2
Explanation

If we let n=2n = 2, then there are a total of 66 integers (3, 5, 6, 9, 10, 12) that can be represented with at most k=4k = 4 bits with exactly n=2n = 2 bits set:

Code 1
3 = 0011
5 = 0101
6 = 0110
9 = 1001
10 = 1010
12 = 1100

The average of these numbers is 7.57.5, which rounds down to 77. Thus, n=2n = 2.

Example 2
Input 2
3 2
Output 2
1
Explanation

If we let n=1n = 1, then there are a total of 33 integers (1, 2, 4) that can be represented with at most k=3k = 3 bits with exactly n=1n = 1 bit set:

Code 2
1 = 001
2 = 010
4 = 100

The average of these numbers is 2.332.33, which rounds down to 22. Thus, n=2n = 2.

Example 3
Input 3
7 90
Output 3
5
Explanation

If we let n=5n = 5, then there are a total of 2121 integers that can be represented with at most k=7k = 7 bits with exactly n=5n = 5 bits set. These numbers sum to 19051905 and averages to 90.7190.71, which rounds down to 9090. Thus, n=5n = 5.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.