进制转换中1的个数--E

来源:互联网 发布:stc单片机iap选型 编辑:程序博客网 时间:2024/06/06 04:45

NowCoder总是力争上游,凡事都要拿第一,所以他对“1”这个数情有独钟。爱屋及乌,他也很喜欢包含1的数,例如10、11、12……。不仅如此,他同样喜欢任意进制中包含1的数。当然,其中包含1的个数越多他越喜欢。你能帮他统计一下某个数在特定的进制下1的个数吗?

#include <stdio.h> int main(){    int N,r;    int count;    while((scanf("%d %d",&N,&r))!=EOF){        count=0;        while(1){            if(N%r==1){                count++;            }            N/=r;            if(!N)                break;        }        printf("%d\n",count);    }    return 0;}


0 0
原创粉丝点击