Uva 10916 - Factstone Benchmark
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 Factstonerating 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
#include<stdio.h> #include<math.h> #define BASE 1960 int main() { int y, i, n; double times, sum; while(scanf("%d", &y) != EOF && y != 0) { for(i=1; (i-1)*10+BASE<=y; ++i); n = (int)pow((double)2, (double)i); times = 1.0*n*log10((double)2); for(sum=0, i=1; ; i++) { sum += log10((double)i); if(sum > times) break; } printf("%d\n", --i); } return 0; }
解题思路:
题目的意思是想让你根据题目的背景,通过计算出给定的年代里那是计算机内存里可以表示多少位数(二进制),然后得到能够存储进去的最大的十进制数得到能小于或者等于这个数的n的阶乘的n
差点让我用上大数的方法了,转换成另外一种思路同样也是可以达到目的了,学习了
更多内容请关注个人微信公众号 物役记 (微信号:materialchains)
作者:雪影蓝枫
本文版权归作者和博客园共有,欢迎转载,未经作者同意须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。