题目传送门: LightOJ 1045

就是求n!在base进制下有多少位。

数论题,查到了斯特林[striling]公式这个东西:lnN!=NlnN-N+0.5ln(2N*pi)

所以base进制下的位数为[(lnN!/ln(base))]

数学真是神奇=-=

###Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//By Brickgao
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
long long t, base, caseno = 1, ans;
double tmp, n;
scanf("%lld", &t);
while(t--)
{
scanf("%lf%lld", &n, &base);
if(n != 0)
{
tmp = n * log(n) - n + 0.5 * log(4 * n * acos(0.0));
tmp = tmp / log(base);
ans = tmp;
if(tmp - (double)ans > 0) ans++;
}
else
ans = 1;
printf("Case %lld: %lld\n", caseno ++, ans);
}
return 0;
}