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;
}