HDU 1018 Big Number

题目大意:求一个数的阶乘的位数。

单词积累:factorial 阶乘

题解:我们知道log10(n!)+1就是n的阶乘的位数,转化一下,log10(n!)+1=log10(1)+log10(2)+log10(3)+……+1;

#include <cstdio>
#include <cmath>
int main(){
    int n;
    scanf("%d",&n);
    while(n--){
        int m;
        double len=0;
        scanf("%d",&m);
        for(int i=1; i<m+1; i++)
        len+=(log10(i+0.0));
        printf("%d
",int(len)+1);
    }
    return 0;
}

总结:double(log(i)/log(10))-->log10(i+0.0)

 

原文地址:https://www.cnblogs.com/forever97/p/3524830.html