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;
    }

     
  • 相关阅读:
    一个星期自动态的网站设计
    java特权制度设计篇
    mac默认截图、截图代码
    NSDateFormatter
    vlan 以及 Linux实现的IEEE 802.1Q VLAN
    gtk+blade+anjuta 的简单实例
    NetBSD是个开源到源码的系统
    创作gtk源码级vim帮助文档 tags
    linux 怎么使用一个c/c++库
    linux 终端控制-- 多彩输出 格式排版
  • 原文地址:https://www.cnblogs.com/honeybusybee/p/5224177.html
Copyright © 2011-2022 走看看