N的阶乘末尾0的数量

给定一个正整数N,求N的阶乘的末尾有几个0。
如N=10时,N!=3628800,末尾两个0


经典题目

package suanfa;

import java.util.Scanner;

public class CountEndZero {
	
	public int countNumber(int n){
		
		int count=0;
		int five=5;
		while(n/five!=0){
			
			count+=n/five;
			five*=5;
			
		}
		
		return count;
		
	}
	
	public static void main(String[] args) {
		
		CountEndZero count=new CountEndZero();
		Scanner scanner=new Scanner(System.in);
		while(true){
		int n=scanner.nextInt();
		System.out.println("the result is "+count.countNumber(n));
		}
	}

}

 

你可能感兴趣的:(0的数量)