1 #include<stdio.h> 2 3 int main() 4 { 5 int n,m,s,t; 6 while(~scanf("%d",&t)) 7 { 8 while(t--) 9 { 10 scanf("%d%d",&n,&m); 11 s=0; 12 while(n>=m) 13 { 14 s+=n/m; 15 n/=m; 16 } 17 printf("%d ",s); 18 } 19 } 20 } 21
1 #include<stdio.h> 2 3 int main() 4 { 5 int n,m,s,t; 6 while(~scanf("%d",&t)) 7 { 8 while(t--) 9 { 10 scanf("%d%d",&n,&m); 11 s=0; 12 while(n>=m) 13 { 14 s+=n/m; 15 n/=m; 16 } 17 printf("%d ",s); 18 } 19 } 20 } 21