zoukankan      html  css  js  c++  java
  • hdu1018大数

    /*
    Big Number
    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 17223    Accepted Submission(s): 7703
    
    
    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
    */
    #include<iostream>
    using namespace std;
    int main()
    {
        int n,k;
        while(scanf("%d",&n)!=EOF)
        {
            while(n--)
            {
                int num=0;
                double ans=1.0;
                scanf("%d",&k);
                for(int i=1;i<=k;i++)
                {
                    ans*=i;
                    while(ans/10>=1)
                    {
                        ans=ans/10;
                        num++;
                    }
                }
                while(ans/10>=1)
                {
                    ans=ans/10;
                    num++;
                }
                num++;    
                printf("%d\n",num);
            }
        }
        return 0;
    }
    # include <stdio.h>
    # include <math.h>
    const double PI=3.1315926;
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int sum=1;
            double n;
            scanf("%lf",&n);
            sum+=(int)((0.5*log(2*PI*n)+n*log(n)-n)/log(10.0));
            printf("%d\n",sum);
        }
    }
     
    /*
    ps:简单是简单,可是前提是你必须知道斯特林公式这鬼东西,不然暴力果断会爆掉。
    
    斯特林公式 : n!≈(√(2*π*n))*((n/e)^n)
    取以10为底的对数*/
    
    
    
    
    
  • 相关阅读:
    Win7 中出现图标显示不全或消失的解决方法
    动态控制ToolStrip上ToolStripButton的图标大小
    TS——类型断言
    TS——函数的类型
    TS之对象类型——接口
    TS——联合类型
    Git文件合并
    1-1、作用域深入和面向对象
    webStrom2017.1版本如何添加vue.js插件
    二:搭建一个webpack3.5.5项目:建立项目的webpack配置文件
  • 原文地址:https://www.cnblogs.com/heqinghui/p/2785007.html
Copyright © 2011-2022 走看看