hdu 1141次方转log
来源:互联网 发布:社会工程学知乎手机号 编辑:程序博客网 时间:2024/06/06 02:26
题目:
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.
题目大意: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.
从1960开始是4位的芯片,以后每十年翻2倍,现在输入年份,找到最大的n,使得n!<=芯片内存。
如1960年,4!>2的4次,3!<2的4次,所以用3表示。
思路:因为到了2160年,它的位数已经是4*2的20次,用普通的数据肯定会超.
当前时间为y,芯片的位数为s=4<<(y-1960)/10;每左移1位,等于翻倍。
i!<2^(s),取对数,log1+log2+log...i<s*log2,求最大的i;对数函数log,以e(2.71828)为底,之前一直以为以2为底。。错了
#include<iostream>#include<cmath>using namespace std;int main(){ int y; while (cin >> y&&y != 0) { y = (y - 1960) / 10; int s = 4; s <<= y; double q = 0; int i = 1; while (q < s) { q += log(++i)/log(2);//对数函数log,以e(2.71828)为底 } cout << i - 1 << endl; } return 0;}
阅读全文
0 0
- hdu 1141次方转log
- num的n次方 O(log(n))
- HDU-幂次方取尾数
- 用log(N)的解法实现数值的整数次方
- 数值的整数次方(剑指offer)O(log n)
- Leading and Trailing(巧妙利用log解决次方问题)
- 次方
- hdu 4578 Transformation(线段树维护区间次方和)
- HDU 1063 Exponentiation 浮点数的幂次方
- HDU 1709 The Balance【负次方母函数】
- hdu 1060 Leftmost Digit(幂次方最高位)
- hdu 4059 数论+高次方求和+容斥原理
- Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)(转)
- Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)(转)
- Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)(转)
- Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)(转)
- Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)(转)
- Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)(转)
- H5游戏和手游APP的差异在哪里?
- 按键唤醒kernel系统-e3x0-button
- Android桌面快捷方式的实现
- nfs文件的储存
- 有必要知道的 24 个 JavaScript 面试题
- hdu 1141次方转log
- Rainbond:开源无服务器PaaS
- 测试报告(包括测试总结)
- QDockWidget用法
- 《20171212》
- log4js-node在VisualStudioCode内置调试控制台无输出解决
- 《数字技术》连载8: 第2章 数字器件 第3节 DTL门电路
- DNS解析过程
- 记一次jar包Netty冲突过程的解决 hadoop2.7.3与ElasticSearch6.0.0