[LeedCode OJ]#172 Factorial Trailing Zeroes
2015-08-24 14:48
176 查看
【 声明:版权所有,转载请标明出处,请勿用于商业用途。 联系信箱:libin493073668@sina.com】
题目链接:https://leetcode.com/problems/factorial-trailing-zeroes/
题意:
返回n的阶乘后面0的个数
思路:
我们知道1~n中2的倍数肯定比5的个数多,所以我们的问题而所有的0无非都是由5的倍数与2的倍数相乘而来
那么问题就转换为n内5的个数
题目链接:https://leetcode.com/problems/factorial-trailing-zeroes/
题意:
返回n的阶乘后面0的个数
思路:
我们知道1~n中2的倍数肯定比5的个数多,所以我们的问题而所有的0无非都是由5的倍数与2的倍数相乘而来
那么问题就转换为n内5的个数
class Solution { public: int trailingZeroes(int n) { int cnt = 0; while(n) { cnt+=n/5; n/=5; } return cnt; } };
相关文章推荐
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) C(组合数+容斥)
- ubuntu编译airplay
- [LeedCode OJ]#70 Climbing Stairs
- svn cleanup failed–previous operation has not finished; run cleanup if it was interrupted
- contains选择器
- WebLogic11g-半小时让你的domain集群化
- hdu5009 Paint Pearls(离散+线性dp)
- 木马常用AIP函数
- HDU 1039.Easier Done Than Said?【字符串处理】【8月24】
- ORA-09925: Unable to create audit trail file
- POJ 1995 Raising Modulo Numbers(快速幂,同余定理)
- 模型选择准则之AIC和BIC
- Raising Modulo Numbers(poj 1995 快速幂)
- Raising Modulo Numbers(poj 1995 快速幂)
- assign、retain、copy使用异同
- POJ--1995--Raising Modulo Numbers
- Raising Modulo Numbers
- quartz 关联多个JobDetail和SimpleTrigger多任务调度
- TLD(Tracking-Learning-Detection)学习与源码理解之(main)
- 1215-Cannot add foreign key constraint