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;
    }
  • 相关阅读:
    运营商公网
    任务管理器 的 服务与进程
    QQ通信原理及QQ是怎么穿透内网进行通信的?
    windows Telnet 客户端常用命令介绍
    redis优化
    shell反射
    USB安装centos6系统(centos7需要换软件)
    rocketmq双主模式
    golang数据类型与转换
    golang介绍
  • 原文地址:https://www.cnblogs.com/baidongtan/p/2664506.html
Copyright © 2011-2022 走看看