shunfurh
编程介的小学生
2018-12-27 13:00
采纳率: 92.7%
浏览 309

这个问题,,用C语言解决,计算二进制的位数的问题,很难

Problem Description
If the quantity of '1' in a number's binary digits is n, we call this number a n-onebit number. For instance, 8(1000) is a 1-onebit number, and 5(101) is a 2-onebit number. Now give you a number - n, please figure out the sum of n-onebit number belong to [0, R).

Input
Multiple test cases(less than 65). For each test case, there will only 1 line contains a non-negative integer n and a positive integer R(n≤1000,0<R<21000), R is represented by binary digits, the data guarantee that there is no leading zeros.

Output
For each test case, print the answer module 1000000007 in one line.

Sample Input
1 1000

Sample Output
7

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • caozhy
    已采纳
    点赞 评论
  • qq_39510244
    笑靥如桃花 2018-12-27 05:46

    #include
    int main( )
    {
    int shuru;
    int buf;
    int jishu=0;
    scanf("%d",&shuru);
    buf=shuru;
    while(buf>0)
    {
    buf=chufa(buf);
    jishu++;
    }

    printf("%d有%d位2进制",shuru,jishu);
    return 0 ;
    

    }
    int chufa(int m)
    {
    int k;
    k=m/2;
    return k;
    }

    点赞 评论

相关推荐