100的阶乘末尾有多少个零?请各位写一下程序貌似LONG类型都存不下不知怎么办了希望有个高效的方法小弟再次感谢

解决方案 »

  1.   

    def tt(n)
      return 1 if n==0 || n==1
      n*tt(n-1)
    end
    p tt(100)
    93326215443944152681699238
    85626670049071596826438162
    14685929638952175999932299
    15608941463976156518286253
    69792082722375825118521091
    6864000000000000000000000000
      

  2.   


    private static int f(int n) {
    int sum = 0;
    int m = n / 5;
    if (n % 5 == 0) {
    if (m % 5 == 0) {
    sum += f(m);
    }
    sum += m;

    return sum;
    }
      

  3.   


    private static int f(int n) {
    int sum = 0;
    int m = n / 5;
    while (m != 0) {
    sum += m;
    m /= 5;
    }
    return sum;
    }这样应该对了吧
      

  4.   


    import java.util.ArrayList;import javax.swing.JOptionPane;public class Test{    /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
         factorial(100);
        }
         public static void factorial(int value) {  
                  ArrayList result = new ArrayList();  
                  int carryBit = 0;  
            
                  result.add(new Integer(1));  
                  for (int out = 2; out <= value; out++) {  
                      for (int in = 0; in < result.size(); in++) {  
                          int temp = ((Integer) result.get(in)).intValue() * out  
                                  + carryBit;  
                          result.set(in, new Integer(temp % 10));  
                          carryBit = temp / 10;  
                      }  
                      while (carryBit != 0) {  
                          result.add(new Integer(carryBit % 10));  
                          carryBit = carryBit / 10;  
                      }  
                  }  
                  StringBuffer sb=new StringBuffer(result.size());  
                  for(int i=0;i<result.size();i++)  
                  {  
                      sb.append(result.get(i));  
                  }  
                  sb=sb.reverse();  
                  System.out.println("result="+sb);  
                  System.out.println("结果位数:"+result.size());  
         }
    }http://slmi.javaeye.com/blog/479406
      

  5.   

    同意21楼,这题如果笔算就这么算比较妙。
    java学习交流群:20378027。欢迎大家加入。
      

  6.   


    public static void main(String[] args){
    int data = 100; //求data阶乘末尾包含多少个0.
    int i = 5 ;
    int count = 0;
    while(data/i!=0) {
    count+=(data/i);
    i*=i;
    }
    System.out.println(data+"阶乘末尾0个数是:"+ count);
    }
    http://topic.csdn.net/u/20090218/12/60066a91-d558-4f4e-afdb-8380c688a056.htmlCSDN上有人问过这个问题 - -!