题解 | #阶乘末尾0的数量#
阶乘末尾0的数量
http://www.nowcoder.com/practice/aa03dff18376454c9d2e359163bf44b8
- 从底向上,一次计算,其实是属于增量式计算因子5的数量
class Solution { public: /** * the number of 0 * @param n long长整型 the number * @return long长整型 */ long long thenumberof0(long long n) { // write code here if(n<=4){ return 0; } long long res = 0; long long divisor = 5; while(divisor<=n){ res += n/divisor; divisor *= 5; } return res; } };