2^k binary number

Source: Internet
Author: User

"Title description"

Set R is a 2^k number and meets the following conditions:

(1) R is at least a 2-bit 2^k binary number;

(2) as the number of 2^k, except the last one, each of the R is strictly less than its right adjacent to the next bit;

(3) After the R is converted to 2 Q, the total number of digits of Q does not exceed W;

Here, the positive integers K (1≤k≤9) and W (K < w≤30000) are given beforehand.

Ask the number of different r that meet the above conditions.

Let us explain from another angle:

Set S is a 01 string with a length of W (that is, the string s is composed of W "0" or "1"), s corresponds to Q in the above condition (3). The S is divided from right to several segments of length k, each corresponding to a number of 2^k, if s can be divided into at least 2 segments, then s corresponding to the binary number can be converted to the 2^k number R.

Example: Set k=3,w=7. Then R is an octal number (2^3=8). Because of w=7, 01 strings of length 7 are divided by 3 bits, which can be broken into 3 segments (i.e. 1, 3, 3, the first segment on the left has only one bits), then the octal number that satisfies the condition is:

(1) 2 digits:

The high position is 1:6 (i.e. 12, 13, 14, 15, 16, 17);

The high position is 2:5;

······

The high level is 6:1 (i.e. 67);

Total 6+5+ A +1=21.

(2) 3 digits:

The high can only be 1,

The 2nd place is 2:5 (i.e. 123, 124, 125, 126, 127);

The 2nd place is 3:4;

······

The 2nd place is 6:1 (i.e. 167);

Total 5+4+ A +1=15.

So, the r that satisfies the requirement has a total of 15+21=36.

"Input description"

Only 1 lines, two positive integers, separated by a space: K, W.

"Output description"

a total of 1 lines, is a positive integer, for the calculated result, that satisfies the condition of the number of different R (in decimal number), the highest bit must not be 0, the numbers must not be inserted in addition to the number of characters (such as spaces, line breaks, commas, etc.) (a positive integer as a result may be large, but not more than 200 bits).

"Sample Input"

3 7

"Sample Output"

36

2^k binary number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.