题解:
n!k进制的位数
首先考虑n!十进制的位数
=log10(n!)
然后用阶乘近似公式
继而换底
得到答案
代码:
#include<bits/stdc++.h> using namespace std; typedef long double ld; const ld pi=acos(-1.0),e=exp(1),eps=1e-10; ld log(ld a,ld b){return log(a)/log(b);} int n,k; int main() { while (~scanf("%d%d",&n,&k)) if (n<=10000) { double ans=0.0; for (int i=1;i<=n;i++)ans+=log(i); ans/=log(k); ans=ceil(ans+eps); printf("%.0lf\n",ans); } else printf("%lld\n",(long long)(0.5*log(2*pi*n,k)+n*log(n,k)-n*log(e,k))+1); }