lintcode_2 Trailing Zeros
2016-06-26 12:33
260 查看
Write an algorithm which computes the number of trailing zeros in n factorial.
Example
11! = 39916800, so the out should be 2
思路是统计2和5的个数,5出现的次数明显比2少,所以统计5 的个数便可~
class Solution {
public:
// param n : description of n
// return: description of return
long long trailingZeros(long long n) {
long long num_of_zero = 0;
while (n >= 5) {
n/=5;
num_of_zero+=n;
}
return num_of_zero;
}
};
Example
11! = 39916800, so the out should be 2
思路是统计2和5的个数,5出现的次数明显比2少,所以统计5 的个数便可~
class Solution {
public:
// param n : description of n
// return: description of return
long long trailingZeros(long long n) {
long long num_of_zero = 0;
while (n >= 5) {
n/=5;
num_of_zero+=n;
}
return num_of_zero;
}
};
相关文章推荐
- 人工智能作业homework5------naive bayes/svm文本分类
- 【转载】Multithreaded toolkits: A failed dream? From Sun VP Graham Hamilton's Blog
- CodeForces 567A Lineland Mail
- 职责链模式(Chain of Responsibility)
- 解决:HttpClient导致应用出现过多Close_Wait的问题
- This implementaion is not part of the windows platform fips validated cryptographic algorithms.
- pip/easy_install failure: failed to create process
- 2016 Al-Baath University Training Camp Contest-1(gym101028)
- From detailed models to formal spiking neurons
- UART Explained(转载)
- 【USACO题库】4.2.1 Drainage Ditches草地排水
- 李开复:人工智能可能会让一半人失业
- wait 和waitpid 的使用
- 解密谷歌机器学习忍者项目,如此培养人工智能人才
- saiku踩坑记录
- Leetcode 11 Container With Most Water
- saiku与kylin整合备忘录
- Shiro系统权限管理、及原理剖析
- C preprocessor fails sanity check
- RAID和mdadm