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. 16S 基础知识、分析工具和分析流程详解

    工作中有个真理:如果你连自己所做的工作的来龙去脉都讲不清楚,那你是绝对不可能把这份工作做好的. 这适用于任何行业.如果你支支吾吾,讲不清楚,那么说难听点,你在混日子,没有静下心来工作. 检验标准:随时 ...

  2. 1月28日周日,更新ruby到2.5.0版,rvm更新。

    在学习Array的方法的时候,发现文档concat方法可以进行多个数组的添加,而我的不行,猜测是ruby版本没有更新. 查询2.31ruby版本的concat方法,果然和2.5版本的不一样. 于是准备 ...

  3. km板子(二分图最大权匹配)

    //#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast,no-stack- ...

  4. Oracle11g温习-第一章 3、ORACLE逻辑结构

    2013年4月27日 星期六 10:27 Oracle逻辑结构的相关数据字典: 记录各个表空间的详细信息. SYS @ prod > select tablespace_name,status ...

  5. Leetcode 784

    //这代码可真丑陋,但我学到了两点1:char和string可以无缝互相转换2:char可以直接加减数字进行转换string不行 class Solution { public: vector< ...

  6. 013PHP文件处理——filemtime filectime fileatime date_default_timezone_set touch

    <?php /** * filemtime filectime fileatime date_default_timezone_set touch */ /*filemtime:获取文件的修改时 ...

  7. 3DES加密解密

    C#3DES加密解密,JAVA.PHP可用 using System; using System.Security.Cryptography; using System.Text; namespace ...

  8. Pycharm(一)下载安装

    https://www.python.org/downloads/windows/ 这里下载python,建议2.7,3.6都下载 Download Windows x86 web-based ins ...

  9. L1-035 情人节

    以上是朋友圈中一奇葩贴:“2月14情人节了,我决定造福大家.第2个赞和第14个赞的,我介绍你俩认识…………咱三吃饭…你俩请…”.现给出此贴下点赞的朋友名单,请你找出那两位要请客的倒霉蛋. 输入格式: ...

  10. 怎样更新PE内的工具

    准备工作:1.    UltraISO - 下载:http://yunpan.cn/Q5XuHwG4ydv85 (访问密码:6263) 2.    7-zip - 下载:http://yunpan.c ...