hdu _p1018 BigNumber
2013-11-22 15:39
225 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1018
分析: stirling数的应用
stirling公式:
Len= log10 (n!) +1;
注意: 因为math.h中的log是以自然对数为底的所以应该换底,同时注意利用对数对公式的化简。
代码:
//hdu 1018 Big Number(n! digits stirling)
#include <stdio.h>
#include <math.h>
#include <iostream>
#define pai acos(-1.0)
using namespace std;
int main()
{
int t,n;
int len;
double tmp;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
tmp=0.5*log(2*pai*n) + n*log(n*1.0) - n;
len=(int)(tmp/log(10.0))+1;
printf("%d\n",len);
}
return 0;
}
分析: stirling数的应用
stirling公式:
Len= log10 (n!) +1;
注意: 因为math.h中的log是以自然对数为底的所以应该换底,同时注意利用对数对公式的化简。
代码:
//hdu 1018 Big Number(n! digits stirling)
#include <stdio.h>
#include <math.h>
#include <iostream>
#define pai acos(-1.0)
using namespace std;
int main()
{
int t,n;
int len;
double tmp;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
tmp=0.5*log(2*pai*n) + n*log(n*1.0) - n;
len=(int)(tmp/log(10.0))+1;
printf("%d\n",len);
}
return 0;
}
相关文章推荐
- HDU-1018 BigNumber
- HDU ACMSteps 2.3.2 BigNumber
- HDU 2896 病毒入侵 AC自动机
- HDU-3308 LCIS 线段树 区间处理
- hdu 3962 Microgene
- hdu~2795~线段树
- HDU 2196 树状DP
- HDU 4316 凸包+半面相交
- hdu 4638 Group(线段树,离线维护左边界,4级)
- hdu 1429 胜利大逃亡(续)
- hdu 3065 AC自动机模版题
- hdu 2066:一个人的旅行
- hdu 1171
- HDU题目分类啊!!!
- HDU 4952 Number Transformation 数论
- HDU 4778 Gems Fight! 状态压缩dp
- HDU 1342 Lotto 【DFS】
- HDU 4585 ShaoLin 基础Treap
- HDU 2955
- hdu 4868 树分治