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;
    }
  • 相关阅读:
    win7开启硬盘AHCI
    (32)odoo中的编码问题
    (31)odoo中的时间
    (30)odoo中的快捷标签
    css3 移动端页面全屏旋转,横屏显示。
    Turn.js 实现翻书效果
    WebStorm 2016 最新版激活(activation code方式)
    vue 状态管理vuex(九)
    webstorm中.vue报错(es6语法报错)-转
    Robot Framework自动化测试(一)
  • 原文地址:https://www.cnblogs.com/baidongtan/p/2664506.html
Copyright © 2011-2022 走看看