版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/luyehao1/article/details/83751473
题目链接:
题意:
求 n! 的位数,1<=n<=1e7。
思路:
solve1:
一个正整数n,它的位数 = 。
那么 n! 的位数 =
solve2:
斯特林公式:
Code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 2e5+10;
int n;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
double cnt=0;
for(int i=2;i<=n;i++){
cnt+=log(i)/log(10);
}
ll ans=floor(cnt);
ans++;
printf("%lld\n",ans);
}
return 0;
}