zoukankan      html  css  js  c++  java
  • HDU 1018(数学题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1018

    Big Number

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 27548    Accepted Submission(s): 12526

    Problem Description
    In many 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 ≤ 107 on each line.
     
    Output
    The output contains the number of digits in the factorial of the integers appearing in the input.
     
    Sample Input
    2
    10
    20
     
    Sample Output
    7
    19
     
     
    题目大意:求一个数阶乘的位数。
    分析:原本以为是一道大数题,其实是一道简单的数学题,需要用到“斯特灵”公式,log(n!)=log1 + log2 + ... + logn。
     
     1 #include <cstdio>
     2 #include <cmath>
     3 using namespace std;
     4 
     5 int main ()
     6 {
     7     int n,m,i;
     8     double sum;
     9     scanf ("%d",&n);
    10     while (n--)
    11     {
    12         scanf ("%d",&m);
    13         sum = 0;
    14         for (i=1; i<=m; i++)
    15         {
    16             sum += log10((double)i);
    17         }
    18         printf ("%d
    ",(int)sum+1);
    19     }
    20     return 0;
    21 }
    View Code
  • 相关阅读:
    Evanyou Blog 彩带
    Evanyou Blog 彩带
    Evanyou Blog 彩带
    Evanyou Blog 彩带
    Evanyou Blog 彩带
    Evanyou Blog 彩带
    Evanyou Blog 彩带
    MFC/.NET
    学习小结——记于华为2018届校园招聘宣讲会之后
    槽点今天未想到
  • 原文地址:https://www.cnblogs.com/dxd-success/p/4242478.html
Copyright © 2011-2022 走看看