---
# System prepended metadata

title: \#172 Factorial Trailing Zeroes
tags: [leetcode, leetcode-easy]

---

# \#172 Factorial Trailing Zeroes
## *計算出n!的尾數有多少個零*
## Log
 - build 20210417 by syhuang

## 解法
 - 見註解
```javascript=
var trailingZeroes = function(n) {
    //基本原理:10的質因數分解為2*5,因此只要找到n!是由幾對"2*5"所組成,就可以知道尾數有幾個零
    //2的數量會遠大於5的數量,因此只要找出n!由多少個5相乘即可
    var result = 0;
    while(n >= 5){
        result += parseInt(n/5);
        n /= 5;
    }
    return result;
};
```

## 備註
## 參考
###### tags: `leetcode`, `leetcode-easy`