码迷,mamicode.com
首页 > 其他好文 > 详细

nefu26(求数的位数)

时间:2016-05-11 19:42:44      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

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\n",(int)res+1);
    }
    
    return 0;
}

 



nefu26(求数的位数)

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!