题意:http://www.lightoj.com/volume_showproblem.php?problem=1045

log10(n!)=log10(n)+log10(n-1)+...+log10(1);  乘加除减

对几取余 就是多少进制

logm(n!)=logm(n)+logm(n-1)+...+logm(1);

换底公式 logm(n!)=log10(n!)/log10(m);

只需要打表出log10(n!)就好 然后除以log10(m);

因为我们知道log10(100)=2   所以要再加1就是结果

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include<vector>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define N 1000006
double a[N];
int main()
{
    int T,t=1,n,m;
    scanf("%d",&T);
    a[0]=0.0;
    for(int i=1;i<N;i++)
        a[i]=a[i-1]+log10(i);
    while(T--)
    {
        scanf("%d%d",&n,&m);
        printf("Case %d: %d\n",t++,(int)(a[n]/log10(m))+1);
    }
    return 0;
}

 

posted on 2017-10-23 10:11  云胡不喜。  阅读(108)  评论(0编辑  收藏  举报