number of length time limit: Ms | Memory limit: 65535 KB Difficulty: 1 description
N. Factorial is a very large number, we all know that the formula is n!=n* (N-1) ... *2*1. Now your task is to calculate N. Number of digits (decimal). Enter n for the first line to indicate how many sets of test data (N<10)
Subsequent n rows enter a set of test data for each row N (0 < N < 1000000) output for each number n, the (decimal) digits of the output n!. Sample input
3
1
3
32000
Sample output
1
1
130271
Using the Sterling formula,
L=LOG10 (2*pi*m)/2+m*log10 (m/e) +1;
M for the required m!
L is the number of bits of m!.
#include <stdio.h>
#include <math.h>
#define PI cos ( -1)
#define e 2.71828182846
int main ( void)
{
int n,i,l,m;
while (scanf ("%d", &n) ==1)
{for
(i=1;i<=n;i++)
{
scanf ("%d", &m);
if (m<=3)
l=1;
else
l=log10 (2*pi*m)/2+m*log10 (m/e) +1;
printf ("%d\n", L);
}
}
return 0;
}