# Poj 1423 Big Number

Source: Internet
Author: User

Big Numberhttp: // poj.org/problem? Id = 1423

 Time Limit:1000 MS Memory Limit:65536 K Total Submissions:24637 Accepted:7895

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 <= m <= 10 ^ 7 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`

Source

Dhaka 2002 train of thought: log10 (n !) = Log10 (1*2*3... * N) = log10 (1) + log10 (2) +... + Log10 (n)

Method 1: use space for time and open an array to save the result!
```# Include "stdio. h "# include" math. h "# include" string. h" # define N 8000000 double a [N]; void Inti () {int I; a [0] = 0; for (I = 1; I

Method 2: n! = Sqrt (2 * π * n) * (n/e) ^ n) * (1 + 1/(12 * n) + 1/(288 * n) + O (1/n ^ 3) π = acos (-1) e = exp (1) both sides take the logarithm of 10
Ignore log10 (1 + 1/(12 * n) + 1/(288 * n) + O (1/n ^ 3) ≈ log10 (1) = 0 get the formula
Log10 (n !) = Log10 (sqrt (2 * pi * n) + n * log10 (n/e ).

# Include "stdio. h"
# Include "math. h"
# Include "string. h"
# Define N 80000
Int main ()
{
Int t, n, I;
Double s, pi, e;
Pi = acos (-1 );
E = exp (1 );
Scanf ("% d", & t );
While (t --)
{
Scanf ("% d", & n );
S = log10 (sqrt (2 * pi * n) + n * log10 (n/e );
If (n = 1)
S = 1;
Printf ("% d \ n", (int) ceil (s ));
}
Return 0;
}

```
Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.