# \#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`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up