这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1141
转换成对数来求解,这里先通过年数求出bit位,然后通过bit位求出2^bit,即最大范围。
n! <= 2^bit即可~~~
代码:
// Author: Tanky Woo
// Blog: www.WuTianQi.com
// Title: HDOJ 1141 Factstone Benchmark
// About: 数学题,用对数省去大数的麻烦
#include
#include
#include
#include
#include
using namespace std;
int main()
{
int year;
while(cin >> year && year)
{
int t = (year-1960)/10 + 2;
t = 1 << t; // t位可以表示的范围
//cout << t << endl;
double ans = 0;
int i;
for(i=1; ; ++i)
{
ans += log((double)i)/log(2.0);
if(ans > t)
break;
}
//cout << ans << endl;
cout << i-1 << endl;
}
return 0;
}