题解 UVA10916 【Factstone Benchmark】

· · 题解

题目

UVA10916 Factstone Benchmark 居然是紫题

大意

给定 x,求出最大的 m 使得 m!\le2^{2^{\lfloor\frac{x-1940}{10}\rfloor}}

分析

在这里,我们的做法有:

我们选用第二种方法。

#include <cstdio>
#include <cmath>
int solve(int year)//处理函数
{
    double computerMax=log10(2.0)*pow(2.0,(year-1940)/10);//计算机能达到的极限的 log 值。
    double test=0;//阶乘的 log 值。
    int ans;//答案
    for(ans=1;computerMax>=test;ans++)//在阶乘小于等于计算机极限时循环。
        test+=log10(ans*1.0);//阶乘处理
    return ans-2;//返回不小于时的值。
}
int main()
{
    int year;
    while(scanf("%d",&year),year)//在 year 不等于 0 时处理。
        printf("%d\n",solve(year));
    return 0;
}