zoukankan      html  css  js  c++  java
  • nefu26(求数的位数)

    Description

    根据密码学需要,要计算某些数的阶乘的位数.

    Input

    第一行为整数n ,接下来 n 行, 每行1个数m (1 ≤ m ≤ 10^7) . 
    
    
    
    

    Output

    输出m的阶乘的位数.

    Sample Input

    2
    10
    20

    Sample Output

    7
    19

    思路:求n的位数:(int)log10(n)+1, log(a*b)=log(a)+log(b)
    #include <cstdio>
    #include <cmath>
    using namespace std;
    int main()
    {
        int n;
        scanf("%d",&n);
        while(n--)
        {
            int m;
            scanf("%d",&m);
            double res=0.0;
            for(int i=1;i<=m;i++)
            {
                res+=log(i)/log(10);
            }
            printf("%d
    ",(int)res+1);
        }
        
        return 0;
    }


  • 相关阅读:
    简易计算机
    作业-继承
    exception
    作业-窗口
    作业-数字
    作业8
    作业9-1
    作业9-2
    book
    成绩录入
  • 原文地址:https://www.cnblogs.com/program-ccc/p/5483200.html
Copyright © 2011-2022 走看看