Water King hegemony

Source: Internet
Author: User

Description

In order to enrich the campus network life, the school BBS held a water king tournament. After the game began, the contestants are crazy irrigation, all want to win the title of water King This honor. But the school BBS is so fragile, only 1e-3 seconds overload.
Now it's time to assemble the water from the runners and reduce the server load.
This is the way things are handled:
Assuming that each runner is 1L per irrigation, each time water is poured, the server collects the 1L water with a virtual container of unlimited capacity.
Finally, there are n containers in the server that collect water. The server can load up to k a container containing water. However, the server has only one self-help measure: to merge two containers of the same amount of water into one of these two easy ones, and another empty direct free it.
However, the existence of this situation can not be ruled out: by way of self-help, only by the players to fill the N container water can not just well collected into no more than K-empty containers to install. For example, when n=3,k=1, in any case collected, can only get the capacity of 1L and 2L of two non-empty containers, it is impossible to meet the requirements of the 1 non-empty containers. Fortunately, the server also has a little space, allowing you to recharge a number of times water, so that the BBS back to normal. Save the virtual world in the server this arduous and glorious task falls on you.

Input

There are 1000 sets of input data, one row for each set of input data, two positive integers n, K, where n does not exceed 10,000,000,k no more than 1,000. Output

Output at least need to continue the number of irrigation, if it is not possible to save the server, output-1. Sample Input

3 1
13 2
1000000 5
Sample Output

1
3
15808
0

 #include <iostream> #include <cmath> using namespace std;
    int main () {int n,k,i,power[25],flag,ans;
        while (scanf ("%d%d", &n,&k)!=eof) {flag=0,ans=0;
        for (i=0;i<25;i++) {if (n& (1<<i)) power[flag++]=1<<i;
        } if (K>=flag) ans=0;
            else {int aa=flag-k;
            ANS=POWER[AA];
        for (i=0;i<aa;i++) ans-=power[i];
    printf ("%d\n", ans);
return 0; }

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.