天天看點

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

​​University of Waterloo Local Contest 2005.09.24​​

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;
}