大数阶乘的位数

 1 import java.util.*;
 2 import java.math.*;
 3 class Main
 4 {
 5     public static void main(String args[])
 6     {
 7         Scanner cin=new Scanner(System.in);
 8         int i,n,m,des=0;
 9         double sum,e=2.7182818284590452354,PI=3.141592653589793239;
10         while(cin.hasNext())
11         {
12             n=cin.nextInt();
13             while(n-->0)
14             {
15                 m=cin.nextInt();
16                 if(m<100000)
17                 {
18                     for(sum=0,i=1;i<=m;i++)
19                     {
20                         sum+=Math.log10(i);
21                     }
22                 }
23                 else
24                 {
25                     sum=Math.log10(Math.sqrt(2*PI*m))+m*Math.log10(m/e);
26                 }
27                 des=(int)sum;
28                 if(des<=sum)des++;
29                 System.out.println(des);
30             }
31         }
32     }
33 }

 

posted @ 2012-08-22 13:07  疼痛落在指尖  阅读(184)  评论(0编辑  收藏  举报