HDU 1018 Big Number (数学题)

时间:2021-07-30 07:36:01

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1018

解题报告:输入一个n,求n!有多少位。

首先任意一个数 x 的位数 = (int)log10(x) + 1;

所以n!的位数 = (int)log10(1*2*3*.......n) + 1;

= (int)(log10(1) + log10(2) + log10(3) + ........ log10(n)) + 1;

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;
const int maxn = +;
double ans[maxn]; double dabiao(int n)
{
double temp = ;
for(int i = ;i <= n;++i)
temp += log10((double)i);
return temp;
}
int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
printf("%d\n",(int)dabiao(n) + );
}
return ;
}