国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

172. Factorial Trailing Zeroes

2019-11-08 02:37:36
字體:
供稿:網(wǎng)友

題目

Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in logarithmic time complexity.

Credits: Special thanks to @ts for adding this PRoblem and creating all test cases.

Subscribe to see which companies asked this question.


思路

計算n的階乘的最后有幾個零,就是計算因數(shù)中2和5的最小個數(shù),5的個數(shù)肯定比2的少,就是計算因數(shù)中5的個數(shù)


代碼

class Solution {public: int trailingZeroes(int n) { //計算n的階乘的最后有幾個零,就是計算因數(shù)中2和5的最小個數(shù),5的個數(shù)肯定比2的少,就是計算因數(shù)中5的個數(shù) if(n <= 4) { return 0; } int times = 0; while(n) { times += n/5; n /= 5; } return times; }};
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宜兴市| 裕民县| 阜城县| 顺义区| 梨树县| 曲周县| 康马县| 临澧县| 淮南市| 丰镇市| 龙江县| 竹溪县| 武陟县| 湖南省| 龙州县| 涿鹿县| 定远县| 吴忠市| 长沙县| 治多县| 淮滨县| 淳安县| 西和县| 寿宁县| 铜川市| 彩票| 凤阳县| 响水县| 宜昌市| 涪陵区| 甘孜县| 镇安县| 临洮县| 衡阳县| 阳新县| 车致| 崇阳县| 江陵县| 桂阳县| 应城市| 南雄市|