题意:N!的阶乘末尾有几个零。
思路:能产生零的只有2*5=10,所但是2的个数是绝对比5多的,所以只需知道5的个数。
代码:
package theEndOfN_阶乘;
public class theEndOfN_阶乘 {
public static int solve(int N) {
int count = 0;
for(int i = 1 ; i <= N ;i++){
int j = i ;
while (j %5 == 0) {
count++;
j = j/5;
}
}
return count;
}
public static void main(String[] args) {
int N = 10;
System.out.println(new theEndOfN_阶乘().solve(N));
}
}