Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!.

题目意思:

n求阶乘以后,其中有多少个数字是以0结尾的。

方法一:

class Solution:
# @return an integer
def trailingZeroes(self, n):
res = 0
if n < 5:
return 0
else:
return n/5+ self.trailingZeroes(n/5)

方法二:

class Solution:
# @return an integer
def trailingZeroes(self, n):
res = 0
x = 5
while( n >= x):
res += n/x
x *= 5
return res

参考博文:http://www.tuicool.com/articles/RZZnQf

n!后缀0的个数 = n!质因子中5的个数 = floor(n/5) + floor(n/25) + floor(n/125) + ....

LeetCode Factorial Trailing Zeroes Python的更多相关文章

  1. [LeetCode] Factorial Trailing Zeroes 求阶乘末尾零的个数

    Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...

  2. LeetCode Factorial Trailing Zeroes

    原题链接在这里:https://leetcode.com/problems/factorial-trailing-zeroes/ 求factorial后结尾有多少个0,就是求有多少个2和5的配对. 但 ...

  3. 关于[LeetCode]Factorial Trailing Zeroes O(logn)解法的理解

    题目描述: Given an integer n, return the number of trailing zeroes in n!. 题目大意: 给定一个整数n,返回n!(n的阶乘)结果中后缀0 ...

  4. [LeetCode] Factorial Trailing Zeroes 阶乘末尾0

    Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...

  5. Python3解leetcode Factorial Trailing Zeroes

    问题描述: Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 ...

  6. LeetCode Factorial Trailing Zeroes (阶乘后缀零)

    题意:如标题 思路:其他文章已经写过,参考其他. class Solution { public: int trailingZeroes(int n) { <? n/: n/+trailingZ ...

  7. LeetCode 172. 阶乘后的零(Factorial Trailing Zeroes)

    172. 阶乘后的零 172. Factorial Trailing Zeroes 题目描述 给定一个整数 n,返回 n! 结果尾数中零的数量. LeetCode172. Factorial Trai ...

  8. 【LeetCode】172. Factorial Trailing Zeroes

    Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. Note: Your ...

  9. LeetCode Day4——Factorial Trailing Zeroes

    /* * Problem 172: Factorial Trailing Zeroes * Given an integer n, return the number of trailing zero ...

随机推荐

  1. [Java学习] 再谈Java包

    在Java中,为了组织代码的方便,可以将功能相似的类放到一个文件夹内,这个文件夹,就叫做包. 包不但可以包含类,还可以包含接口和其他的包. 目录以"\"来表示层级关系,例如 E:\ ...

  2. [Java学习] Java super关键字

    super 关键字与 this 类似,this 用来表示当前类的实例,super 用来表示父类. super 可以用在子类中,通过点号(.)来获取父类的成员变量和方法.super 也可以用在子类的子类 ...

  3. English trip -- VC(情景课)8 D Reading

    Listen and read. Shop Smart [smɑːt]  Employee of the Month: Sara['særə] (萨拉) Lopez(洛佩斯) Congratulati ...

  4. 玲珑杯 ACM热身赛 #2.5 A 记忆化搜索+瞎搞

    #include <cstdio> #include <vector> #include <iostream> #include <algorithm> ...

  5. Confluence 6 连接到一个 LDAP 目录

    https://www.cwiki.us/display/CONFLUENCEWIKI/Connecting+to+an+LDAP+Directory

  6. Mac搭建个人服务器开发微信公众号

    个人电脑搭建小型服务器面临的一个重要问题就是网络问题,我把解决的过程简单记录一下,准备以后参考. 1. 内网穿透 由于个人所在网络是一个局域网,没有公网的IP,因此在公网是不能直接访问个人电脑的服务器 ...

  7. .NET 性能优化方法总结==转

    .NET 性能优化方法总结 目录 目录 1. C#语言方面... 4 1.1 垃圾回收... 4 1.1.1 避免不必要的对象创建... 4 1.1.2 不要使用空析构函数 ★... 4 1.1.3 ...

  8. POJ 1166 暴力搜索 即 枚举

    e.... 米还是没有读懂题....T_T ..... e.... 这就是传说中的暴力吗....太血腥了....太暴力了...九重for循环....就这么赤裸裸的AC了.... 水是水了点..但是.. ...

  9. anroid学习目录总结

    当前标签: Android开发学习总结   Android开发学习总结(六)—— APK反编译 孤傲苍狼 2015-07-26 12:48 阅读:4245 评论:5     Android开发学习总结 ...

  10. Django(五)在模板中使用静态文件

    location 最后一个文件夹名就是project名,我用了Django_Plan. Application 是自动加入的APP名字,我用了Plan 静态文件相关配置: Django_Plan\se ...