#-*- coding: UTF-8 -*-
#给定一个整数N,那么N的阶乘N!末尾有多少个0? 比如:N=10,N!=3628800,N!的末尾有2个0。
#所有的尾部的0可以看做都是2*5得来的,所以通过计算所有的因子中2和5的个数就可以知道尾部0的个数。
#实际上,2的个数肯定是足够的,所以只需计算5的个数即可。
#要注意,25=5*5是有两个5的因子;125=5*5*5有3个5的因子。比如,计算135!末尾0的个数。
#首先135/5 = 27,说明135以内有27个5的倍数;27/5=5,说明135以内有5个25的倍数;
#5/5=1,说明135以内有1个125的倍数。
#当然其中有重复计数,算下来135以内因子5的个数为27+5+1=33。
class Solution(object):
    def trailingZeroes(self, n):
        """
        :type n: int
        :rtype: int
        """
        result=0
        while n>0:
            n=n/5
            result+=n
        return result

sol=Solution()
sol.trailingZeroes(10)

转载于:https://www.cnblogs.com/kwangeline/p/5953541.html

【leetcode❤python】172. Factorial Trailing Zeroes相关推荐

  1. 【LeetCode】172 - Factorial Trailing Zeroes

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

  2. LeetCode 172. Factorial Trailing Zeroes

    LeetCode 172. Factorial Trailing Zeroes 问题来源LeetCode 172. Factorial Trailing Zeroes 问题描述 Given an in ...

  3. 172. Factorial Trailing Zeroes

    /**172. Factorial Trailing Zeroes *2016-6-4 by Mingyang* 首先别忘了什么是factorial,就是阶乘.那么很容易想到需要统计* (2,5)对的 ...

  4. leetcode python3 简单题172. Factorial Trailing Zeroes

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百七十二题 (1)题目 英文: Given an integer n, retu ...

  5. Leetcode 172 Factorial Trailing Zeroes

    1.题目要求 Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be ...

  6. LeetCode(172) Factorial Trailing Zeroes

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

  7. Leet Code OJ 172. Factorial Trailing Zeroes [Difficulty: Easy]

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

  8. 172 Factorial Trailing Zeroes(阶乘后的零)————附带详细思路和代码

    文章目录 0 效果 1 题目 2 思路 3 代码 0 效果 1 题目 Given an integer n, return the number of trailing zeroes in n!. N ...

  9. 【leetcode❤python】Move Zeroes

    #-*- coding: UTF-8 -*- #filter()函数可以对序列做过滤处理,就是说可以使用一个自定的函数过滤一个序列, #把序列的每一项传到自定义的过滤函数里处理,并返回结果做过滤.最终 ...

最新文章

  1. MAVEN项目环境搭建
  2. 微信小程序中显示空格
  3. 为什么要学jquery
  4. 简易listview与adapter实现列表,ArrayAdapter和BaseAdapter
  5. C++(17)--详解const
  6. 源码编译mysql5.5_源码编译安装MySQL5.5
  7. java jsp动作_Java中级—JSP九大内置对象和动作
  8. 创建查看mysql8.0数据库_创建和选择数据库
  9. mysql 汉字拼音怎么获得_mysql汉字拼音取法
  10. KNN算法(10折交叉验证)
  11. 联想S3机子密码设置
  12. 适合产品经理的桌面壁纸-分类神器
  13. 已解决-内部版本7601 此windows副本不是正版
  14. webpack打包处理字体文件
  15. linux 定时任务 数量 性能,Linux 性能测试与分析
  16. Python网络编程自动化(HCIA)
  17. 测试语文水平的软件,语文试卷质量分析
  18. CSP-2019day1题解报告
  19. Flutter中解决AndroidX包与Support包冲突问题
  20. 产品与解决方案的问题。

热门文章

  1. 关于Keras在测试不能使用正则dropout的解决
  2. springboot 获取控制器参数的几种方式
  3. java线程中的notifyAll唤醒操作
  4. c++11 lambda
  5. 软件测试——性能测试、压力测试、负载测试等详解
  6. XCode5添加新建类模板(Cocos2dx Template Class for Scene or Layer)
  7. 【转载】MOS开关(verilog)
  8. 管理信息系统数据库设计标准(草稿)
  9. 男生给女生最牛B的告白
  10. SQL语句:建表语句、插入语句、查询语句、增加列、删除列、查询语句like、修改语句