输入N求N的阶乘的10进制表示的长度。例如6! = 720,长度为3。
Input
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 1000)
第2 - T + 1行:每行1个数N。(1 <= N <= 10^9)
Output
共T行,输出对应的阶乘的长度。
Input示例
3
4
5
6
Output示例
2
3
3
没什么好说的,斯特林近似公式。
N=1的时候特判一下。
不过没判也能够,应该是没有这组数据。
下面是计算N!的位数的公式:
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<ctime>
#include<string>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#include<set>
#include<map>
#include<cstdio>
#include<limits.h>
#define MOD 1000000007
#define fir first
#define sec second
#define fin freopen("/home/ostreambaba/文档/input.txt", "r", stdin)
#define fout freopen("/home/ostreambaba/文档/output.txt", "w", stdout)
#define mes(x, m) memset(x, m, sizeof(x))
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define INF 1e9+7
#define Pi 4.0*atan(1.0)
#define lowbit(x) (x&(-x))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-12;
using namespace std;
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
inline int read(){
int x(0),f(1);
char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return x*f;
}
ll Stirling(int n)
{
if(1 == n){
return 1;
}
ll res = log10(n*2*Pi)/2 + (ll)n*log10(n/exp(1.0)) + 1;
return res;
}
int main()
{
int T, n;
T = read();
while(T--){
n = read();
printf("%lld\n", Stirling(n));
}
return 0;
}