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