1.简述:
输入一个正整数n,求n!(即阶乘)末尾有多少个0? 比如: n = 10; n! = 3628800,所以答案为2
输入为一行,n(1 ≤ n ≤ 1000)
输出一个整数,即题目所求
输入:
10
输出:
2
2.代码实现:
public class Main{
public static int test(int n){
if(n < 0){
return 0;
}
int res = 0;
while (n !=0){
res += n /5;
n = n/5;
}
return res;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {
System.out.println( test(in.nextInt()));
}
}
}