zoukankan      html  css  js  c++  java
  • hdu Big Number

    Big Number

    Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 480    Accepted Submission(s): 330
     
    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
     
     
    Source
    Asia 2002, Dhaka (Bengal)
     
    Recommend
    JGShining

    分析:此题为斯特林公式的应用。斯特林公式如下:

    取对数:lg(n!) = (lg(2*pi)+lg(n))/2 + n*(lg(n)-lg(e))

    #include<iostream>
    #include<cmath>
    
    using namespace std;
    
    int main()
    {
        int test,n;
        long long int s;
        const long double c1 = 0.798179868358; //lg(2*pi)
        const long double c2 = 0.434294481903; //lg(e)
        long double c3;
        cin >> test;
        while(--test+1)
        {
            cin >> n;
            c3 = log10((double)n);
            s = 1;
            if(n > 3)
            {
                s = (c3 + c1)/2 + n * (c3 - c2) + 1;
                cout << s << endl;
            }
            else
                cout << 1 << endl; 
        }
        return 0;
    }
  • 相关阅读:
    幸运序列(lucky) 模拟
    無名(noname) 字符串
    香港记者 图论
    Jmeter接口测试系列之参数化方法
    jmeter接口测试-总结
    python字符串
    python变量
    7.15-ROS可视化工具-标记
    6.22-Actionlib
    7.1-Move_base 参数调整
  • 原文地址:https://www.cnblogs.com/baidongtan/p/2664506.html
Copyright © 2011-2022 走看看