Nyoj Title 69 Number of Lengths

Source: Internet
Author: User
Tags time limit
number of length time limit: Ms | Memory limit: 65535 KB Difficulty: 1 description

N. Factorial is a very large number, we all know that the formula is n!=n* (N-1) ... *2*1. Now your task is to calculate N. Number of digits (decimal). Enter n for the first line to indicate how many sets of test data (N<10)
Subsequent n rows enter a set of test data for each row N (0 < N < 1000000) output for each number n, the (decimal) digits of the output n!. Sample input

3
1
3
32000
Sample output
1
1
130271

Using the Sterling formula,
 
L=LOG10 (2*pi*m)/2+m*log10 (m/e) +1;
M for the required m!
L is the number of bits of m!.

 
#include <stdio.h>
#include <math.h>
#define PI cos ( -1)
#define e 2.71828182846
int main ( void)
{
    int n,i,l,m;
    while (scanf ("%d", &n) ==1)
    {for
        (i=1;i<=n;i++)
        {
            scanf ("%d", &m);
            if (m<=3)
                l=1;
            else
            l=log10 (2*pi*m)/2+m*log10 (m/e) +1;
            printf ("%d\n", L);
        }
    }
    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.