链接:https://www.nowcoder.com/acm/contest/75/A
来源:牛客网
题目描述
夫夫有一天对一个数有多少位数感兴趣,但是他又不想跟凡夫俗子一样,
所以他想知道给一个整数n,求n!的在8进制下的位数是多少位。
所以他想知道给一个整数n,求n!的在8进制下的位数是多少位。
输入描述:
第一行是一个整数t(0<t<=1000000)(表示t组数据) 接下来t行,每一行有一个整数n(0<=n<=10000000)
输出描述:
输出n!在8进制下的位数。
输入
3 4 2 5
输出
2 1 3
斯特林公式的应用(不懂的看我斯特林公式的转载)
斯特林公式
其实是ceil(x)或写成 unsigned long long(x+1)
x<2要自己判断一下,因为精度问题
cin关闭同步也TLE,无语了
#include <iostream>
#include <cstdio>
#include <cmath>
const double pi=acos(-1);
typedef unsigned long long ull;
using namespace std;
int main() {
int t;
scanf("%d",&t);
//ios::sync_with_stdio(false);
//cin>>t;
while (t--) {
ull n,x=1;
scanf("%llu",&n);
//cin>>n;
if(n>1)
x=ull(log(sqrt(2*pi*n))/log(8)+n*log(n/exp(1))/log(8)+1);
printf("%llu\n",x);
}
return 0;
}