POJ 1423 Big Number

Source: Internet
Author: User

Topic Source Description

In many applications very large integers numbers is required. Some of these applications is using keys for secure transmission of data, encryption, etc. In this problem you is given a number, you has to determine the number of digits in the factorial of the number.

In many applications, you need to use very large integers. Some of these applications are using keys for secure data transfer, encryption, and so on. In this problem, you get a number, you have to determine the number of digits of the factorial of Input

The input consists of several lines of integers. The first line contains an integer n, which is the number of cases to be tested, followed by n lines, one integer per line, 1 <= m <= 10^7 Output

The output contains the number of digits of the factorial of the integer that appears in the input. Sample Input

2
20
Sample Output
7
19
Source

Dhaka 2002 Analyze

The test is Stirling formula ...

z = x ^ y = = y = LOGX Z
We know the number of bits of n is (LG N) + 1

When n is very large, n! Close to sqrt (2 * PI * N (n/e) ^n).

Take the logarithm on both sides:

LG n! = (LG 2PIn)/2 + n * LG N/E

So:

N! The number of bits is: res = (LG 2PIn)/2 + N * LG n/e + 1; Code

 #include <iostream> #include <cmath> using namespace std;
Const double e = 2.7182818284590452354, pi = 3.141592653589793239;     Double Strling_digits_num (int n) {return log10 (2*pi*n)/2.0+n* (log10 (n/e));    0ms//return log10 (sqrt (2 * pi * n)) + N * log10 (n/e);
	16MS} int main () {int t;
	cin>>t;
		while (t--) {int n;
		cin>>n;
		Double m=0;
		M=strling_digits_num (n);
		int answer= (int) m; Attention....
		10 of the N-th side has n+1 digit answer++;
	cout<<answer<<endl;
	} system ("Pause");
return 0; }

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.