problem
172. Factorial Trailing Zeroes
code
class Solution {
public:
int trailingZeroes(int n) {
int ans = 0;
while(n)
{
n /= 5;
ans += n;
}
return ans;
}
};
有多少个零主要是看有多少个2*5,只要是偶数肯定就有一个2,故主要看有多少个5,即是最后的结果。但是怎么求解某个数字有多少个5呢?
100 / 5 = 20;
100 / 25 = 4;
100/ 125 = 0;
即是一个数除以5的幂次的结果的求和。
1. Leetcode_Factorial Trailing Zeroes;