Fork me on GitHub

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

差点让我用上大数的方法了,转换成另外一种思路同样也是可以达到目的了,学习了

posted @   Gifur  阅读(547)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
TOP
点击右上角即可分享
微信分享提示