题解 UVA10916 【Factstone Benchmark】
题目
UVA10916 Factstone Benchmark
居然是紫题
大意
给定
分析
在这里,我们的做法有:
-
使用高精度计算
2^n 和m! 。这种方法虽然可行,但很容易出错,不是我们的主要选择。
-
不使用高精度,直接计算
2^n 和m! 的\log 值。这个做法可以,推荐这样做。
-
打表
这个做法也可以,但是代码要写好长。
我们选用第二种方法。
#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;
}