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;
    }
  • 相关阅读:
    变量的分类
    诫子书
    变量variable
    标识符Identifier
    保留字reserved word
    关键字keyword
    编译运行代码的指令
    创建如下的类,使得运行的话可以输出
    常用的几个命令行操作都有哪些?
    idea快捷键整合-无鼠标操作idea
  • 原文地址:https://www.cnblogs.com/baidongtan/p/2664506.html
Copyright © 2011-2022 走看看