2013
11-28

# Factstone Benchmark

Amtel has announced that it will release a 128-bit computer chip by 2010, a 256-bit computer by 2020, and so on, continuing its strategy of doubling the word-size every ten years. (Amtel released a 64-bit computer in 2000, a 32-bit computer in 1990, a 16-bit computer in 1980, an 8-bit computer in 1970, and a 4-bit computer, its first, in 1960.)
Amtel will use a new benchmark – the Factstone – to advertise the vastly improved capacity of its new chips. The Factstone rating is defined to be the largest integer n such that n! can be represented as an unsigned integer in a computer word.Given a year 1960 ≤ y ≤ 2160, what will be the Factstone rating of Amtel’s most recently released chip?

There are several test cases. For each test case, there is one line of input containing y. A line containing 0 follows the last test case. For each test case, output a line giving the Factstone rating.

1960
1981
0

3
8

mark：最大的处理器位数是2160年的4194304bits。要算n!的二进制表示位，直接算很难，可以变成求log2后取整加1。然后因为log2(n!) = log2(1) + log2(2)…+log2(n)，所以直接O(n)就可以了。大概算到30w可以把500wbits的算出来，之后按输入二分。

# include <stdio.h>
# include <math.h>

int dp[300010] ;

void init()
{
int i ;
double sum = 0 ;
for (i = 2 ; i <= 300000 ; i++)
{
sum += log2(i*1.0) ;
dp[i] = ((int)sum) + 1 ;
}
}

int main ()
{
int n, l, r, mid ;
init() ;
while (~scanf ("%d", &n), n)
{
n = 1 << ((n-1940) / 10) ;
l = 1, r = 300000 ;
while (l<r-1)
{
mid = (l+r)/2 ;
if (dp[mid] < n) l = mid ;
else r = mid ;
}
if (dp[r] == n) l = r ;
printf ("%d\n", l) ;
}
return 0 ;
}

1. 其实国内大部分公司对算法都不够重视。特别是中小型公司老板根本都不懂技术，也不懂什么是算法，从而也不要求程序员懂什么算法，做程序从来不考虑性能问题，只要页面能显示出来就是好程序，这是国内的现状，很无奈。