HDOJ-ACM1018(JAVA)

 

题意:

求n!的位数,0<n<10^7

 

思路:log10(1)+log10(2)+···+log10(n) = log10(n!)   【题目的考点就在这吧】

解题:

import java.util.*;

import java.io.*;

public class Main{

    public static void main(String[] arg){
        Scanner scan = new Scanner(new BufferedInputStream(System.in));
         int N=scan.nextInt();
        while(N--!=0){
            double count = 0;
            int n = scan.nextInt();
            int len = n + 1;
            for(int i = 1 ; i != len ; i ++  ){
                count = count + Math.log10(i);
            }
            System.out.println((int)(count+1));
        }
        scan.close();
    }

}

 

posted on 2016-06-13 19:36  xiezie  阅读(210)  评论(0编辑  收藏  举报

导航