Big number
This problem, there is no difficulty or anything, is to rise posture. Problem DescriptionIn Many applications very large integers numbers are 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.
Inputinput consists of several lines of integer numbers. The first line contains a integer n, which is the number of cases to being tested, followed by n lines, one integer 1≤n≤ 107 on all line.
Outputthe output contains the number of digits in the factorial of the integers appearing in the input.
Sample Input
21020
Sample Output
719
This is a more interesting topic. Give a number and then find the number of bits of the factorial of the number. The first idea must be to find the factorial of the number, and then count the number. And then the egg! Must not be found. Then find the following information:N The order of the number of bits equal to LOG10 (n! ) =LOG10 (1) + ..... LOG10 (N). OK, on the code:
#include <cstdio> #include <cmath>int main () { int n; scanf ("%d", &n); for (int i=0;i<n;i++) { int x; Double sum=0; scanf ("%d", &x); for (int j=1;j<=x;j++) sum+=log10 (j); printf ("%d\n", int (sum) +1); } return 0;}
At the same time find a little information:Stirling formula: n! and √ (2πn) * n^n * e^ (-N) values very close
So log10 (n!) = log (n!)/log (Ten) = (N*log (n)-n + 0.5*log (2*π*n))/log (n);
Here's someone else's code:
#include <stdio.h> #include <math.h>const double PI = ACOs ( -1.0), const double LN_10 = log (10.0);d ouble Reback ( int N) { return ceil ((N*log (double (N))-n+0.5*log (2.0*N*PI))/ln_10);} int main () {int cas,n;scanf ("%d", &cas), while (cas--) {scanf ("%d", &n), if (n<=1) printf ("1\n"), else printf ("% .0lf\n ", Reback (n)); return 0;}
really up the pose!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 1018.Big Number "July 25"