[LeetCode] Factorial Trailing Zeroes
2015-07-13 20:25
549 查看
Question:
Given an integer n, return the number of trailing zeroes in n!.
1、题型分类:
2、思路:寻找n!后面的0的个数,即有多少个2*5,从而需要寻找里面总共有多少个2和多少个5,2肯定比5多,则只要找出5的个数即可。n/5是从n/5到n中5的倍数的个数
3、时间复杂度:
4、代码:
5、优化:
6、扩展:
Given an integer n, return the number of trailing zeroes in n!.
1、题型分类:
2、思路:寻找n!后面的0的个数,即有多少个2*5,从而需要寻找里面总共有多少个2和多少个5,2肯定比5多,则只要找出5的个数即可。n/5是从n/5到n中5的倍数的个数
3、时间复杂度:
4、代码:
public class Solution { public int trailingZeroes(int n) { int cnt=0; while(n>0) { cnt+=n/5; n/=5; } return cnt; } }
5、优化:
6、扩展:
相关文章推荐
- Project Euler:Problem 60 Prime pair sets
- LightOJ 1070 Algebraic Problem (推导+矩阵快速幂)
- OC 基础之----属性
- CPaintDC 、CWindowDC、 CClientDC、 CDC的区别与联系
- Swiper使用方法(向前和向后按钮在swiper-container外面)
- SonarQube安装完后出现SonarQube is under maintenance. Please check back later.
- LOJ 1070 - Algebraic Problem(矩阵快速幂啊)
- 【转载】Foxmail 小技巧 25则 (转载)
- POJ 3691 DNA repair 基于AC自己主动机DP
- 人工智能计算器AI Calculator 3.3.0 详细破解思路&教程
- 在rails中pluck和select和collect区别
- installation error: unknown failure
- copy, retain, assign , readonly , readwrite,strong,weak,nonatomic整理
- HD 1151Air Raid
- LightOJ 1070 - Algebraic Problem 矩阵快速幂
- ubuntu 下配置发送邮件(sendmail/msmtp+mtt)
- Kafka设计解析(三):Kafka High Availability (下)
- Kafka设计解析(二):Kafka High Availability (上)
- The Material Sourcing Process Failed To Create Picking Suggestions in INVTOTRX (文档 ID 2003806.1)
- NBUT 2015 ACM Trainning Contest-11038 Problem A How many Points 解题报告