Big number
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 25567 accepted submission (s): 11600
Problem description
In specified 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.
Input
Input 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 ≤0 ≤ 107 on each line.
Output
The output contains the number of digits in the factorial of the integers appearing in the input.
Sample Input
21020
Sample output
719
Question: n! Number of digits
Analysis:
N! Number of digits
= [Lg (N!)] + 1 = [lg (1) + lg (2) +... + Lg (n)] + 1 // [] indicates an integer.
= (INT) Ceil (n * ln (N)-N + 0.5 * ln (2 * n * π)/ln (10) // Ceil is rounded up
Expansion:
// Ceil (n) is the smallest integer greater than or equal to the value n.
// Floor (n) is the maximum integer less than or equal to the value n.
// For a number in B, you only need to take the logarithm of B to obtain the number of digits in B (decimal number after the logarithm is obtained, so we still need to get the integer and then + 1)
<Span style = "font-family: fangsong_gb2312; font-size: 24px;"> <strong> # include <stdio. h> # include <math. h> int main () {int I, j; int N, A; double sum; scanf ("% d", & N); for (I = 0; I <n; I ++) {scanf ("% d", & A); sum = 0.0; For (j = 1; j <= A; j ++) sum + = log10 (j); // take the logarithm printf ("% d \ n", (INT) sum + 1); // Add one after the integer} return 0 ;} </strong> </span>