lintcode 2:尾部的零
2017-12-13 21:10
435 查看
题目描述
设计一个算法,计算出n阶乘中尾部零的个数分析
这其实是一个数学题,只有2和5这两个因子相乘才会在尾部产生0,2的数量比5的数量多得多,因此只需统计所有数中因子5有多少个就行了。代码
public class Solution { /* * @param n: An integer * @return: An integer, denote the number of trailing zeros in n! */ public long trailingZeros(long n) { // write your code here, try to do it without arithmetic operators. long res = 0; while(n>0){ res+=n/5; n=n/5; } return res; } }
相关文章推荐
- LintCode 2.尾部的零
- LintCode【简单】2. 尾部的零 。代码及思路
- 【计算连乘积中末尾0的个数】LintCode 尾部的零
- lintcode-2-尾部的零
- [Lintcode] #2 尾部的零
- LintCode 2.尾部的零
- Lintcode 2. 尾部的零
- LintCode Python 尾部的零
- Lintcode 尾部零的个数
- (lintcode)第2题尾部的零
- lintcode 2.尾部的零
- LintCode_002_尾部的零
- Lintcode 2: 尾部的零
- LintCode笔记(6)——尾部的零
- LintCode_002_尾部的零
- python - LintCode 2. 尾部的零
- lintcode第二题 计算n阶乘中尾部零的个数
- [LintCode] 尾部的零
- Lintcode 尾部的零
- LintCode 第二题 计算阶乘结果尾部的零