Zoj 1526 | poj 1423 big number (Stirling formula for large numbers)

Source: Internet
Author: User

In specified applications very large integers numbers arerequired. some of these applications are using keys for Secure Transmission ofdata, encryption, etc. in this problem you are given a number, you have todetermine the number of digits in the factorial
The number.

Input

Input consists of several lines of integer numbers. the first line contains aninteger N, which is the number of cases to be tested, followed by n lines, oneinteger 1 <= n <= 10 ^ 7 on each line.

Output

The output contains the number of digits in the factorial of the integersappearing in the input.

Sample Input

2
10
20

Sample output

7
19

Question:

Given a number N, N is required! .

Analysis

 

In general, tooooooooooooold

Therefore, it may be considered as a big number problem. In fact, it can be considered as a big number problem, but generally, the processing of large numbers will exceed the space.

In fact, there is another way to solve this problem. In that case, this would be a question. However, the first time I came into contact with the log function to find the length of the number and the sterling formula, it would be of great significance.

Sterling formula:

In the case of N, the sterling formula will be more accurate. The specific derivation can be seen in Baidu encyclopedia.

Formula for calculating the length of M: The number of digits of M is equal to the integer plus 1.

Len = (INT) log10 (m) + 1

 

 

Library Function log

 
# Include <iostream> # include <math. h> using namespace STD; const Double E = 2.718281828459; const double Pi = 3.1415926535898; int main () {Longlong N, TT; CIN> tt; while (tt> 0) {TT --; CIN> N; Longlong ans = (Longlong) (double) log10 (SQRT (2 * pI * n) + N * log10 (N/E )) + 1; cout <ans <Endl;} return0 ;}

Contact Us

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.