【水题-数学】 HDU 1141 Factstone Benchmark
来源:互联网 发布:开票软件任务是什么 编辑:程序博客网 时间:2024/06/02 13:13
1141 ( Factstone Benchmark )
Problem Description
Amtel has announced that it will release a 128-bit computer chip by 2010, a 256-bit computer by 2020, and so on, continuing its strategy of doubling the word-size every ten years. (Amtel released a 64-bit computer in 2000, a 32-bit computer in 1990, a 16-bit computer in 1980, an 8-bit computer in 1970, and a 4-bit computer, its first, in 1960.)Amtel will use a new benchmark - the Factstone - to advertise the vastly improved capacity of its new chips. The Factstone rating is defined to be the largest integer n such that n! can be represented as an unsigned integer in a computer word.
Given a year 1960 ≤ y ≤ 2160, what will be the Factstone rating of Amtel's most recently released chip?
There are several test cases. For each test case, there is one line of input containing y. A line containing 0 follows the last test case. For each test case, output a line giving the Factstone rating.
Sample Input
1960
1981
0
Sample Output
3
8
说白了,这题就是让你求最大的n,使其满足n!<2^(2^p),这里的p需要先计算出(p=(年份-1960)/10+2)。但是很明显,当年份为2160时,p=22,那么2^(2^p)是多少呢?这个算起来十分麻烦,数据超过了double的范围。那要怎么办呢?能不能把数字变小一些。仔细观察2^(2^p),有两次指数,能不能去掉一次呢?当然可以,取对数!等式两边取对2的对数,就变成了log2(1)+log2(2)+log2(3)+...+log2(n)<2^p。这样就很容易计算了。
#include <iostream>#include <cmath>using namespace std;int main(){ int n; while (cin >> n, n) { int p = (n - 1960) / 10 + 2; p = 1 << p; double sum = 0.0, fac = 1.0; while (sum < (double)p) sum += log(fac) / log(2.0), fac += 1.0; cout << int(fac - 2.0) << endl; } return 0;}
0 0
- 【水题-数学】 HDU 1141 Factstone Benchmark
- 【数学 对数】HDU 1141 Factstone Benchmark
- hdu 1141 Factstone Benchmark(数学:计算)
- HDU 1141 Factstone Benchmark (数学)
- hdu 1141 Factstone Benchmark
- HDU 1141 Factstone Benchmark
- hdu 1141 Factstone Benchmark
- hdu 1141 Factstone Benchmark
- hdu 1141 Factstone Benchmark
- HDOJ HDU 1141 Factstone Benchmark
- ACM--数学--HDOJ 1141--Factstone Benchmark--水
- poj2661 Factstone Benchmark 数学
- HDU 1141 Factstone Benchmark 对数乱搞
- HDU1141 Factstone Benchmark(数学)
- hdoj-1141-Factstone Benchmark
- hdu 1141 Factstone Benchmark 数论水题,,阶乘用斯特林公式
- UVA - 10916 Factstone Benchmark(数学)
- 杭电1141 Factstone Benchmark
- hdu 4924 Football Manager(搜索+剪枝+dp)
- rsync+inotify实现服务器实时备份
- BestCoder #1-1 HDU 4857 逆拓扑排序
- Live555 服务器保存RTSP协议数据为MP4文件
- LAMP---环境搭建
- 【水题-数学】 HDU 1141 Factstone Benchmark
- 二十五:微信公众帐号开发-自定义菜单的view类型(访问网页)
- SQLYog 数据连接配置的迁移
- TCP详解
- 二十六:微信公众帐号开发-应用实例之历史上的今天
- 解析游戏卡顿 影响电脑游戏帧数的因素
- virtualbox---复制虚拟机
- 在Firebug中调试JS程序 (F10 F11 F8)
- 寻找最大数