Factstone Benchmark问题

该程序解决了一个与计算机位数和Factstone评级相关的问题。给定年份,根据Amtel公司每十年字长翻一番的策略,确定对应芯片的位数,并计算其Factstone评级。Factstone评级定义为最大的整数n,使得n!可以在计算机字中表示。程序通过循环和数学计算找到满足条件的n值,并输出Factstone评级。在样例输出中,1960年的评级为3,1981年的评级为8。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目描述

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. 

样例输入

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:

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值