題目信息: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);
}
}