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

题目大意:给出年份,每个10年对应一个当前计算机可支持的字节位数,计算n! < max(max 为当前计算机能表示的最大整数),求最大n.

解题思路:字节数k = (year - 1940) / 10,  问题就转化成 n ! < 2 ^ k < (n + 1) !, 如果单纯模拟会溢出, 所以我们对两边同取对数,因为log(a*b) = log(a) + log(b);所以log(n!) = sum(log(i)), ( 1<= i <= n), 只要找到最小的sum(log(i)) > k * log(2) ,答案就是i- 1.
#include<stdio.h>
#include<math.h> int main(){
int year;
while (scanf("%d", &year), year){
int n = (year - 1940) / 10;
double k = pow ( 2, n) * log10(2), sum = 0;
for (int i = 1; ; i++){
sum += log10(i);
if (sum > k){
printf("%d\n", i - 1);
break;
}
}
}
return 0;}

uva 10916 Factstone Benchmark(对数函数的活用)的更多相关文章

  1. HDU 1141 Factstone Benchmark (数学 )

    题目链接 Problem Description Amtel has announced that it will release a 128-bit computer chip by 2010, a ...

  2. Factstone Benchmark

    [问题描述] Amtel已经宣布,到2010年,它将发行128位计算机芯片:到2020年,它将发行256位计算机:等等,Amtel坚持每持续十年将其字大小翻一番的战略.(Amtel于2000年发行了6 ...

  3. poj 2661 Factstone Benchmark (Stirling数)

    //题意是对于给定的x,求满足n! <= 2^(2^x)的最大的n//两边同取以二为底的对数,可得: lg2(n!) <= 2^x 1.   log2(n!) = log2(1) + lo ...

  4. sicily 1119 Factstone Benchmark

    题意:求满足n! < 2^k,n的最大值! 解题:指数比较转换成对数比较,达到降幂! 其中: log (n!) = log(n)+log(n-1)+...+log(1); log(2^k) = ...

  5. poj 2661 Factstone Benchmark

    /** 大意: 求m!用2进制表示有多少位 m! = 2^n 两边同时取对数 log2(m!) = n 即 log2(1) + log2(2)+log2(3)+log2(4)...+log2(m) = ...

  6. poj2661 Factstone Benchmark(大数不等式同取对数)

    这道题列出不等式后明显是会溢出的大数,但是没有必要写高精度,直接两边取对数(这是很简明实用的处理技巧)得: log2(n!)=log2(n)+log2(n-1)+...+log2(1)<=log ...

  7. Factstone Benchmark(数学)

    http://poj.org/problem?id=2661 题意:Amtel在1960年发行了4位计算机,并实行每十年位数翻一番的策略,将最大整数n作为改变的等级,其中n!表示计算机的无符号整数(n ...

  8. 【poj2661】Factstone Benchmark(斯特林公式)

    传送门 题意: 给出\(x,x\leq 12\),求最大的\(n\),满足\(n!\leq 2^{2^x}\). 思路: 通过斯特林公式: \[ n!\approx \sqrt{2\pi n}\cdo ...

  9. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

随机推荐

  1. thinksns解析1

    1.数据库     这儿是关于数据库的封装,还是挺厉害的,最终select中完成sql语句的封装,最后由query来完成底层api     2.初始化过程 sns也是通过框架完成显示调用,一开始通过i ...

  2. jquery live()只支持css选择器

    昨天在处理过keypress键盘事件后,今天要把用户在页面上动态添加的字段条目加上删除功能,就是在每个字段后面加上一个漂亮的小按钮,当用户点击这个按钮,相应的条目就被从数据库中删除. 为了实现这种功能 ...

  3. Ubuntu 下 安装QQ 截图工具

    1.由于ubuntu下是没有dll动态链接库的,所以需要安装一个软件wine,有这个东西之后,以后在ubuntu下就可以运行exe文件了.(wine是一款优秀的Linux系统平台下的模拟器软件,用来将 ...

  4. VPN ,Bypass the FIrewall

    Bypass the China Firewall Methods November 16th, 2012Posted in , Tech With their assortment of techn ...

  5. System.Reflection.Assembly.GetEntryAssembly()获取的为当前已加载的程序集

    今天在使用System.Reflection.Assembly.GetEntryAssembly()获取程序集时,发现获取的程序集不全.原来是因为C#的程序集为延迟加载,此方法只获取当前已加载的,未加 ...

  6. em(倍)与px的区别(转载)

    在国内网站中,包括三大门户,以及"引领"中国网站设计潮流的蓝色理想,ChinaUI等都是使用了px作为字体单位.只有百度好歹做了个可调的表率.而 在大洋彼岸,几乎所有的主流站点都使 ...

  7. 变更到Android4.4的问题

    更新到Android 4.4,写了个小程序.发现运行不起来了.抛空指针异常.debug模式下,发现在onCreate方法中获取Button是null. Android 4.4把layout进行了重组, ...

  8. poj 2778 DNA Sequence AC自动机DP 矩阵优化

    DNA Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11860   Accepted: 4527 Des ...

  9. Python安装及开发环境配置

    Python的语法简洁,功能强大,有大量的第三方开发包(模块).同时Python不像java一样对内存要求非常高,适合做一些经常性的任务方面的编程.根据codeeval网站数据统计显示,连续三年,Py ...

  10. HttpClient 教程

    前言 超文本传输协议(HTTP)也许是当今互联网上使用的最重要的协议了.Web服务,有网络功能的设备和网络计算的发展,都持续扩展了HTTP协议的角色,超越了用户使用的Web浏览器范畴,同时,也增加了需 ...