题目描述
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?
输入
输出
样例输入
1960
1981
0
样例输出
3
8
题目描述
Amtel 宣布将在 2010 年发布 128 位计算机芯片,到 2020 年发布 256 位计算机,以此类推,继续其每十年字长翻一番的战略。 (Amtel 于 2000 年发布了 64 位计算机,1990 年发布了 32 位计算机,1980 年发布了 16 位计算机,1970 年发布了 8 位计算机,1960 年发布了第一台 4 位计算机。)
Amtel 将使用一个新的基准 - Factstone - 来宣传其新芯片的容量大大提高。 Factstone 评级被定义为最大整数 n,使得 n! 可以表示为计算机字中的无符号整数。
给定年份 1960 ≤ y ≤ 2160,Amtel 最近发布的芯片的 Factstone 评级是多少?
输入
有几个测试用例。 对于每个测试用例,都有一行包含 y 的输入。 包含 0 的行跟在最后一个测试用例之后。
输出
对于每个测试用例,输出一条给出 Factstone 评级的行。
样例输入
1960
1981
0
样例输出
3
8
关于这道题在讲一个什么事情,请看:
//位数的意思是:比如4位可以表示2^4=16个0到15 16个整数
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int y; //y表示年份
int w; //w是指数,2^w表示位数(字长),即len
int n; //n为FactStone评级
int len; //len是字长(位数),
//如w=4,即len=2^4=16,位数为16位,可以表示2^16个整数(0~2^16-1)
while (1) //不断执行循环,跳出条件为输入0,下面写出
{
cin >> y;
if (y == 0) //程序结束执行的条件
{
break;
}
int w = (y / 10) - 194; //w分别取2,3,4,5……
len = pow(2, w); //求出位数(字长)len
n = 1;
double result = 0;
while (result < len*log(2)) //这是纸上推出来的
{
result = result + log(n); //乘法转换为了加法
n++;
}
cout << n - 2 << endl; //关于这里为什么是n-2,请看下面解释
}
return 0;
}
关于为什么是n-2: