题目大意: 给定y,求满足22((y-1960)/10+2) > k!的k的最大值。
解题思路:通过两边同时去对数,达到降幂的效果,使得两边的数能用自带类型存储。
取对数后:2((y-1960)/10+2) * log(2)> log(k!).
进一步转化:2((y-1960)/10+2) > log(k!) / log(2) = log(k) / log(2) + log(k-1)/log(2) + log(k-2) / log(2) + ... +log(1)/log(2).
由于y <= 2160, 所欲(y-1960)/10+2 <= 22,故左边2((y-1960)/10+2)<=222.在自带类型方位内。
最后遍历求解k即可
代码如下:
1 #include <cstdio> 2 #include <cmath> 3 4 5 // reference : http://www.lxway.com/18542861.htm 6 7 // 2^(2^((y-1960)/10+2)) > k! 8 // 2^((y-1960)/10+2) * log(2) > log(k!) = log(k) + log(k-1) + log(k-2) + ... + log(1) 9 int benchmark(int y) { 10 int e = (y - 1960) / 10 + 2; 11 int left = 1 << e; 12 int k = 0; 13 double res = 0; 14 while (left > res) { 15 res += log(++k) / log(2); 16 } 17 return --k; 18 } 19 20 int main() { 21 int y; 22 while (scanf("%d", &y), y) { 23 int k = benchmark(y); 24 printf("%d\n", k); 25 } 26 return 0; 27 }
Reference:
Sicily 1190. Factstone Benchmark
时间: 2024-10-24 21:17:24