HDU 1018 big number

Source: Internet
Author: User
Tags integer numbers
Big number Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others) Total submission (s): 25567 accepted submission (s): 11600

Problem description In specified applications very large integers numbers are required. some of these applications are using keys for secure transmission of data, encryption, etc. in this problem you are given a number, you have to determine the number of digits in the factorial of the number.
 
Input Input consists of several lines of integer numbers. the first line contains an integer N, which is the number of cases to be tested, followed by n lines, one integer 1 ≤ n ≤0 ≤ 107 on each line.
 
Output The output contains the number of digits in the factorial of the integers appearing in the input.
 
Sample Input
21020
 
Sample output
719
  Question: n! Number of digits Analysis: N! Number of digits = [Lg (N!)] + 1 = [lg (1) + lg (2) +... + Lg (n)] + 1 // [] indicates an integer. = (INT) Ceil (n * ln (N)-N + 0.5 * ln (2 * n * π)/ln (10) // Ceil is rounded up
Expansion: // Ceil (n) is the smallest integer greater than or equal to the value n. // Floor (n) is the maximum integer less than or equal to the value n.
// For a number in B, you only need to take the logarithm of B to obtain the number of digits in B (decimal number after the logarithm is obtained, so we still need to get the integer and then + 1)


<Span style = "font-family: fangsong_gb2312; font-size: 24px;"> <strong> # include <stdio. h> # include <math. h> int main () {int I, j; int N, A; double sum; scanf ("% d", & N); for (I = 0; I <n; I ++) {scanf ("% d", & A); sum = 0.0; For (j = 1; j <= A; j ++) sum + = log10 (j); // take the logarithm printf ("% d \ n", (INT) sum + 1); // Add one after the integer} return 0 ;} </strong> </span>


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.