题目信息:http://acm.hdu.edu.cn/showproblem.php?pid=1018
题意:求n阶乘的位数
求n的位数公式:(int)log10(n)+1;
求n阶乘位数就是每个里面相加;
代码如下:
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
int main() {
int t,n;
double ans;
scanf("%d",&t);
while(t--) {
scanf("%d",&n);
ans=0;
for(int i=1; i<=n; i++)
ans+=log10(i);
printf("%d\n",(int)ans+1);
}
}