hdu1141 (Factstone Benchmark(利用对数进行大数比较))
2015-01-22 19:10
330 查看
这个题的意思就是求 N!<2^bit
两边同时取对数,得到 log(N!)<bit*log(2.0),变换形式得到 log(N!)/ log(2.0)<bit;
log(N!)=log(1*2*3*4*……N)=log(1)+log(2)+log(3)+log(4)+……log(N);
则问题转化为求: log(1)/ log(2.0)+ log(2)/ log(2.0)+ log(3)/ log(2.0)+…… log(N)/ log(2.0)<bit
从而避免了大数计算,利用对数直接比较,将问题简单化
两边同时取对数,得到 log(N!)<bit*log(2.0),变换形式得到 log(N!)/ log(2.0)<bit;
log(N!)=log(1*2*3*4*……N)=log(1)+log(2)+log(3)+log(4)+……log(N);
则问题转化为求: log(1)/ log(2.0)+ log(2)/ log(2.0)+ log(3)/ log(2.0)+…… log(N)/ log(2.0)<bit
从而避免了大数计算,利用对数直接比较,将问题简单化
#include<stdio.h> #include<math.h> int main() { int n,i; __int64 t; double ans; while(scanf("%d",&n),n!=0) { t=(n-1960)/10+2; t=1<<t; i=0; ans=0; while(ans<t) { ans+=log((double)(++i))/log(2.0);<span style="color: rgb(0, 130, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px; background-color: rgb(248, 248, 248);">//特别注意 i = 1 ,log(i++)不知道为什么错了 只能i = 0,log(++i)</span> } printf("%d\n",i-1); } return 0; }
相关文章推荐
- hdu1141 Factstone Benchmark(利用对数进行大数比较)
- poj2661 Factstone Benchmark(大数不等式同取对数)
- 【数学 对数】HDU 1141 Factstone Benchmark
- HDU1141 Factstone Benchmark(数学)
- poj 2661 Factstone Benchmark 取对数
- B.10916 - Factstone Benchmark
- UVA 10916 - Factstone Benchmark
- 1119. Factstone Benchmark
- uva 10916 - Factstone Benchmark
- UVa 10916 - Factstone Benchmark
- Factstone Benchmark hoj 数学题
- 10916 - Factstone Benchmark
- SPCAMLEditor使用系列(3)--利用SPCamlEditor实现 时间字段跟当前时间进行实时比较计算
- 1119. Factstone Benchmark
- Uva 10916 - Factstone Benchmark
- 【ACM】杭电1141:Factstone Benchmark
- 利用oracle中的MINUS函数和OVER函数,进行两个记录的比较
- hdu 1141 Factstone Benchmark
- uva 10916 - Factstone Benchmark
- 【日记】利用VB.NET实现MYSQL和MSSQL进行批量插入记录的方法及比较