【HDU】 1018 Big Number
2014-10-12 10:58
281 查看
大意就是求 :
log10(n!) = log10(1 * 2 * 3 * .......*n) = log10(1) + log10(2) + ........+log10(n);
打表的话会MLE,直接递推就行了,后台数据不会很刁钻。
还有一种方法,就是斯特林公式
也就是log10(n!) = log(n!) / log(10) = ( n*log(n) - n + 0.5*log(2*π*n))/log(n);
直接公式就出来了,更快捷。
这里就不多说了。
log10(n!) = log10(1 * 2 * 3 * .......*n) = log10(1) + log10(2) + ........+log10(n);
打表的话会MLE,直接递推就行了,后台数据不会很刁钻。
#include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long LL; const int maxn = 10000000; //double dp[maxn + 1]; //void List(){ // dp[1] = log10(1.0); // for(int i = 2; i < maxn; i++) // dp[i] = dp[i - 1] + log10(1.0 * i); // return; //} int main(){ int T; //List(); scanf("%d",&T); while(T--){ int n; scanf("%d",&n); double ret = 0; for(int i = 1; i <= n; i++) ret += log10(1.0 * i); printf("%.f\n",ceil(ret)); } return 0; }
还有一种方法,就是斯特林公式
也就是log10(n!) = log(n!) / log(10) = ( n*log(n) - n + 0.5*log(2*π*n))/log(n);
直接公式就出来了,更快捷。
这里就不多说了。
相关文章推荐
- hdu 1018 Big Number
- HDU 1018 Big Number N!的位数
- hdu 1018 Big Number_Stirling数求N!的位数
- hdu 1018 Big Number 数学
- HDU 1018-Big Number(数学)
- HDU 1018 Big Number 公式= =
- hdu 1018 big number 求解
- hdu 1018 Big Number
- HDU 1018 Big Number (log函数求数的位数)
- HDU 1018 Big Number(斯特林公式)
- HDU 1018 Big Number【阶乘位数】
- 求位数 hdu 1018 Big Number
- hdu——1018——Big Number
- HDU--1018--Big number!(计算阶乘结果的位数)
- HDU 1018 Big Number(斯特林公式)
- HDU 1018 Big Number
- hdu 1018 Big Number(纯数学公式)
- HDU 1018 Big Number
- HDU - 1018 Big Number
- hdu 1018 big number (有个组合公式)