zoukankan      html  css  js  c++  java
  • Big Number

    Big Number

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

    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
     
    这个题的意思是:给你一个数,让你求出N!由多少位数构成,比如输出10,它的阶乖是3628800 由7位数构成,这时你要输出7;
     
    如果真的求阶乘,将是一个非常大的 数字,这里用对数来求位数。以下是详细代码:

    #include<iostream>
    #include <cmath>
    using namespace std;

    int main()
    {
    int N=0;
    cin>>N;
    while(N--)
    {
    int m=0;
    cin>>m;
    double number=0;//注意不能是int类型
    for(int i=m;i>0;i--)
    {
    number+=log10(i);
    }
    cout<<(int)(number+1)<<endl;
    }
    return 0;
    }

     
  • 相关阅读:
    新版open live writer连接博客园
    github个人博客域名绑定(附带详细原理说明)
    开源性能监控分析工具glowroot
    (转)Python实例手册
    Jetty嵌入式Web容器攻略
    H2数据库攻略
    CAS ticket过期策略
    CAS自定义登录验证方法
    Sonatype Nexus高级配置
    配置sonar、jenkins进行持续审查
  • 原文地址:https://www.cnblogs.com/honeybusybee/p/5224177.html
Copyright © 2011-2022 走看看