The question is:
Log10 (N !) = Log10 (1*2*3 *....... * n) = log10 (1) + log10 (2) + ........ + log10 (N );
If you type a table, it will be MLE and recursive. The background data will not be very smooth.
#include<cmath>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;const int maxn = 10000000;//double dp[maxn + 1];//void List(){// dp[1] = log10(1.0);// for(int i = 2; i < maxn; i++)// dp[i] = dp[i - 1] + log10(1.0 * i);// return;//}int main(){ int T; //List(); scanf("%d",&T); while(T--){ int n; scanf("%d",&n); double ret = 0; for(int i = 1; i <= n; i++) ret += log10(1.0 * i); printf("%.f\n",ceil(ret)); } return 0;}
Another method is the sterling formula.
That is, log10 (N !) = Log (N !) /Log (10) = (N * log (N)-N + 0.5 * log (2 * π * n)/log (N );
The formula is provided, which is faster.
I will not talk about it here.
(HDU) 1018 big number