HDU 1141 Factstone Benchmark (数学)

Factstone Benchmark

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2046    Accepted Submission(s): 1142

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
Source
Recommend
Eddy   |   We have carefully selected several similar problems for you:  1144 1212 1220 1143 1722 

题意:Amtel公司宣布他们会在2010年发行128位元的计算机,在2020年发行256位元的计算机,在这个策略之下往后每10年就发行2倍位元的计算机。(Amtel公司在2000年发行 64位元,1990年发行32位元计算机,1980年发行16位元计算机,1970年发行8位元计算机,1960年发行4位元计算机,也是第一部计算机)。Amtel公司将使用一种新的规格基准 「Factstone」来广告并凸显新一代计算机芯片容量的神速进步。

「Factstone」的等级被定义为:
以一个最大的整数 n 表示,使得 n! 可以在一个计算机字组(word,也就是我们说的多少位元)中
被以 unsigned integer(无号整数)来表示。
例如:在1960年时的计算机为4位元,也就是一个字组能表达 0~15的整数。
而 3! 是在这个范围中最大的阶层数了(4! > 15),所以其「Factstone」等级是 3。
给你一个公元年数 y ,请问最新发行的Amtel计算机其「Factstone」等级是多少?

题解:n! < 2^bit最大的n,其中bit为计算机位数,求n。

           两边对数即可:log(1) + log(2) +...+ log(n) < bit* log(2)。

AC代码:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
//求n! < 2^bit最大的n,其中bit为计算机位数。
//两边对数:log(1) + log(2) +...+ log(n) < bit* log(2)。
int main()
{
	int n; int bit;
	while(~scanf("%d",&n),n)
	{
		int time=(n-1960)/10;
		bit=pow(2.0,1.0*(time+2));
	 double sum=0; int i=1;
    while(1)
    {
		sum+= log10(i*1.0);	
		if(sum>bit*log10(2.0))
		 break;
		i+=1;
	
   }
		printf("%d\n",i-1);
	}
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值