Big number
Time Limit: 20000/10000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 10040 accepted submission (s): 4476
Problem descriptionin response applications very large integers numbers are required. some of these applications are using keys for secure transmission of data, encryption, etc. in this problem you are given a number, you have to determine the number of digits in the factorial of the number.
Inputinput consists of several lines of integer numbers. The first line contains an integer N, which is the number of cases to be tested, followed by n lines, one integer 1 ≤ n ≤ 107 On each line.
Outputthe output contains the number of digits in the factorial of the integers appearing in the input.
Sample Input
21020
Sample output
719
Sourceasia 2002, Dhaka (Bengal)
Recommendjgshining
When I first saw the question, I thought of a large number. However, looking at the question, the data given may reach the level of 10 ^ 7. For such a large number, ask for a factorial! Oh, my God! You know, the 10000000 factorial has more than 60 million digits.
Fortunately, we have a formula,Log10 (N !) = (0.5 * log (2 * pI * n) + N * log (N)-N)/log (10). Here we use log10 (n) = ln (N) /ln (10 );
The formula is named the link http://zh.wikipedia.org/wiki/%E6%96%AF%E7%89%B9%E6%9E%97%E5%85%AC%E5%BC%8F of the sterling formula Wikipedia
# Include <stdio. h> # include <stdlib. h> # include <math. h> # include <string. h> # include <time. h> # define PI 3.1415926int main () {int t; scanf ("% d", & T); While (t --) {int digits, N; scanf ("% d", & N); If (n = 0) // No .. {printf ("1 \ n"); continue;} digits = (INT) (0.5 * log (2 * pI * n) + N * log (N)-N) /log (10); printf ("% d \ n", digits + 1); // Add 1. } Return 0 ;}