题意:给定n、k,求出n的阶乘转化为k进制一共有几位。
思路:log(a*b)=log(a)+log(b)..............
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1045
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <string> 5 #include <algorithm> 6 #include <iostream> 7 using namespace std; 8 const int N=1000010; 9 10 double sum[N]={0,0}; 11 12 int main(){ 13 14 // freopen("data.in","r",stdin); 15 // freopen("data.out","w",stdout); 16 17 int t,i,j,n,k; 18 scanf("%d",&t); 19 for(i=2;i<N;i++) 20 sum[i]=sum[i-1]+log10(i); // log(a*b)=log(a)+log(b) 21 for(i=1;i<=t;i++){ 22 scanf("%d%d",&n,&k); 23 int ans=sum[n]/(log10(k*1.0))+1; 24 printf("Case %d: %d\n",i,ans); 25 } 26 return 0; 27 }