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为底的对数*/
    
    
    
    
    
  • 相关阅读:
    保。,net .
    表格单元格内容超出时显示省略号效果
    延迟加载、异步加载
    requestAnimationFrame,Web中写动画的另一种选择
    淡扯javascript编程思想
    简单粗暴地理解js原型链js面向对象编程
    试试写个随笔吧
    全屏遮罩
    事件绑定
    Metro style Apps 开发第一篇
  • 原文地址:https://www.cnblogs.com/heqinghui/p/2785007.html
Copyright © 2011-2022 走看看