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为底的对数*/
    
    
    
    
    
  • 相关阅读:
    linux服务器安装nginx及使用
    服务器搭建
    Linux安装mysql5.7
    个人服务器的选择
    DECODE函数简介
    ORACLE数据库优化
    Mac下JD-GUI无法使用
    Qt 中QString 字符串操作:连接、组合、替换、去掉空白字符
    [Qt初级] 解决 中QMainWindow和QDockWidget添加布局失败问题
    我的JS 中级学习篇
  • 原文地址:https://www.cnblogs.com/heqinghui/p/2785007.html
Copyright © 2011-2022 走看看