UVa 10916 - Factstone Benchmark

10916 - Factstone Benchmark

 * [ ]

Summary
Given a year, find out what the Amtel processor word size will be in that year, and then figure out the largest $$N$$ for which $$N!$$ will fit in an unsigned integer of that word size.

Explanation
In 1960, the word size was a measly four bits, with the word size doubling every ten years. That means that given the year Y, the number of bits can be calculated as $$2^{2 + \lfloor (Y-1960)/10 \rfloor}$$.

The largest unsigned integer that will no longer fit in K bits is $$2^K$$. For $$N!$$ to fit, then it must clearly be less than that. Now, consider $$\log_2 N! = \log_2 N + \log_2 (N-1) + \ldots + \log_2 1$$. If this quantity is less than $$\log_2 2^K = K$$, then $$N!$$ will fit. This suggests a fairly simple algorithm: given the number of bits K, keep adding $$\log_2 i$$ terms (incrementing i each time) until this number exceeds K. The largest number that still fit is the required Factstone rating.

Solutions

 * Code All the Problems

Input
1960 1981 2160 0

Output
3 8 254016