2. Trailing Zeros
Description
Write an algorithm which computes the number of trailing zeros in n factorial.
Example
11! = 39916800, so the out should be 2
Solution
public class Solution {
/*
* @param n: An integer
* @return: An integer, denote the number of trailing zeros in n!
*/
public static long trailingZeros(long n) {
// write your code here, try to do it without arithmetic operators.
long s = 0;
for(long i=5;n/i>=1;i*=5){
s += n/i;
}
return s;
}
}