查找阶乘JavaScript的尾随零
给定一个整数n,我们必须编写一个函数,该函数返回n!中的尾随零。
例如-
trailingZeroes(4) = 0 trailingZeroes(5) = 1 because 5! = 120 trailingZeroes(6) = 1
示例
const num = 17;
const findTrailingZeroes = num => {
let cur = 5, total = 0;
while (cur <= num) {
total += Math.floor(num / cur);
cur *= 5;
};
return total;
};
console.log(findTrailingZeroes(num));
console.log(findTrailingZeroes(5));
console.log(findTrailingZeroes(1));输出结果
控制台中的输出将是-
3 1 0
热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短