1058 N的阶乘的长度

1058 N的阶乘的长度

基准时间限制:秒 空间限制:131072 KB 

输入NN的阶乘的10进制表示的长度。例如6! = 720,长度为3

Input

输入N(1 <= N <= 10^6)

Output

输出N的阶乘的长度

Input示例

6

Output示例

3

 * n!的长度等于log10(n!)

import java.util.*;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
            int n=sc.nextInt();
            double ans;
            int i;
            ans=1;
            for( i=1;i<=n;i++)
                ans+=Math.log10(i);
               long x=(long)ans;
            System.out.println(x);
        }
         sc.close();
        
    }

}
原文地址:https://www.cnblogs.com/watchfree/p/5350717.html