zoukankan      html  css  js  c++  java
  • ACM HOJ 1018 Big Number

    Big Number

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


    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
     

    Recommend
    JGShining

    斯特灵公式是一条用来取n阶乘近似值数学公式。一般来说,当n很大的时候,n阶乘的计算量十分大,所以斯特灵公式十分好用,而且,即使在

     

    n很小的时候,斯特灵公式的取值已经十分准确。

    公式为:

    这就是说,对于足够大的整数n,这两个数互为近似值。更加精确地:

    或者:

     

     

     

    超强大的公式
    n=2*pi*n)^1/2 *(n/e)^n *e^(a/12*n)
    
     
    

    #include<iostream>

    #include<cmath>

    using namespace std;

    const double PI=acos(-1.0);

    const double e=exp(1.0);

    int main()

    {

        int T,n;

        cin>>T;

        while(T--)

        {

            cin>>n;

            if(n!=1)

              cout<<(int)(0.5*log10(2*PI*n)+n*log10(n/e)+1)<<endl;

            else cout<<1<<endl;

        }

        return 0;   

    }   

     

     

    #include<stdio.h>
    #include
    <math.h>
    using namespace std;
    int main()
    {
    int n,i;
    double sum;
    int T;
    scanf(
    "%d",&T);
    while(T--)
    {
    sum
    =1;
    scanf(
    "%d",&n);
    if(n==1){printf("1\n");continue;}
    for(i=2;i<=n;i++)
    {
    sum
    +=log10((double)i);
    }
    printf(
    "%d\n",(int)sum);
    }
    return 0;
    }

    #include<cmath>
    #include
    <stdio.h>
    #include
    <iostream>
    using namespace std;
    const double PI=acos(-1.0);
    const double e=exp(1.0);
    int main()
    {
    int T,n,i;
    int cnt;
    scanf(
    "%d",&T);
    while(T--)
    {
    scanf(
    "%d",&n);
    if(n==1){printf("1\n");continue;}//这个不能少,否则会错误,WR了好几次
    cnt=(int)(0.5*log10(2*PI*n)+n*log10(n/e)+1);
    printf(
    "%d\n",cnt);

    }
    return 0;
    }

    #include<stdio.h>
    #include
    <cmath>
    using namespace std;
    const double PI=acos(-1.0);
    const double e=exp(1.0);

    int main()
    {
    int n,cnt;
    int T;
    scanf(
    "%d",&T);
    while(T--)
    {
    scanf(
    "%d",&n);
    cnt
    =(int)(0.5*log10(2*PI*n)+n*log10(n/e))+1;
    printf(
    "%d\n",cnt);
    }
    return 0;
    }

  • 相关阅读:
    JQueryEasyUI学习笔记(五)
    创建文本后,写入文本,报“正由另一进程使用,因此该进程无法访问该文件”
    Ogre wiki Application 运行我们的第一个程序
    我想在年前找一份工作
    C#+XAML的Metro应用开发入门(二)
    C#+XAML的Metro应用开发入门(一)
    疑难问题解决备忘录(1)——LAMP环境下WordPress无法发现themes目录下的主题问题解决
    C#+XAML的Metro应用开发入门(一)
    C#+XAML的Metro应用开发入门(三)
    Struts 2+Spring 3+Hibernate 3.3 在MyEclipse 10环境下的整合配置
  • 原文地址:https://www.cnblogs.com/kuangbin/p/2114998.html
Copyright © 2011-2022 走看看