uva10916

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=21&problem=1857&mosmsg=Submission+received+with+ID+10547037

uva10916

Problem B: Factstone Benchmark

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

Output for Sample Input

3
8
题意:来自http://www.nocow.cn/index.php/UVA/10916
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」等级是多少?

[编辑] Input




輸入包含多組測試資料,每組測試資料一列,含有一個整數 y。(1960 <= y <= 2160)
當 y=0 時代表輸入結束。

[编辑] Output




對每一組測試資料輸出一列。輸出在 y 年時最新發行的Amtel電腦其「Factstone」等級是多少。

关键语句  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?

说白了就是求出最大m使得m! <= 2^n,。。。

两边同时取对数有(log1 + log2 + log 3 + .... + log4+..) <= n,对前面的求和比较找出m就可以了
#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
 int n;
 while(scanf("%d",&n)!=EOF)
 {
  if(n==0)
   break;
  int m=(n-1960)/10;
  int i;
  double s=4.0;//s(1960对应的值)的起始值试试4
  for(i=0;i<m;i++)
  {
   s*=2;
  }
  s=s*log10((double)2.0);//对s取对数lg2
  double s2=0;
  for(i=1;;i++)
  {
   s2+=log10((double)i);
   if(s2<=s)
   {
    continue;
   }
   else
    break;
  }
  printf("%d\n",i-1);
 }
 return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值