国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 福建省| 桐梓县| 广州市| 武清区| 张家口市| 德阳市| 扎鲁特旗| 清河县| 宁河县| 廉江市| 拜城县| 临颍县| 沅陵县| 永靖县| 井冈山市| 延津县| 孟州市| 花莲县| 黄大仙区| 长治市| 托克逊县| 海口市| 威宁| 海林市| 哈密市| 抚顺市| 余庆县| 白玉县| 尖扎县| 新建县| 高唐县| 宜君县| 二手房| 津市市| 临邑县| 尉犁县| 图木舒克市| 新竹县| 金秀| 云霄县| 汉阴县|