title | date | categories | tags | mathjax |
---|---|---|---|---|
Trailing Zeros |
2016-06-07 14:34:53 -0700 |
programming_snaps |
pro_magic |
true |
Write an algorithm which computes the number of trailing zeros in n factorial.
class Solution {
public:
// param n : description of n
// return: description of return
long long trailingZeros(long long n) {
long long sum = 0;
while (n != 0) {
sum += n / 5;
n /= 5;
}
return sum;
}
};