Input:
Enter 1 positive integers per line n, (0<n<1000 000)
Output:
For each n, the number of (decimal) digits of the output n!.
Analysis:
This problem uses brute force method. By definition, direct solution!
The so-called n! decimal digits, is log (n) +1, according to the mathematical formula is: n!=1*2*3*.....*n;
LG (n!) =LG (2) +......LG (n);
Code:
Enter a number n, and you calculate the number of decimal digits of the factorial of the digit width//For example: 3! =6, the width is 1//sample data://n=3 output 1//n=32000 output 130271//n=1000000 output 5565709#include <string> #include < iostream> #include <iomanip> #include <stdio.h> #include <cmath>using namespace Std;int main () { long int n; long int i; Double sum; while (scanf ("%ld", &n)!=eof) { sum=0.0; for (i=2; i<=n; i++) { sum+=log10 (i); } printf ("%ld\n", (int) sum+1); } return 0;}
Computes the number of digits of the factorial of a large number n (decimal) (log I accumulation method)