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


原文地址:https://www.cnblogs.com/program-ccc/p/5483200.html