【leetcode❤python】172. Factorial Trailing Zeroes
#-*- 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相关推荐
- 【LeetCode】172 - Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- LeetCode 172. Factorial Trailing Zeroes
LeetCode 172. Factorial Trailing Zeroes 问题来源LeetCode 172. Factorial Trailing Zeroes 问题描述 Given an in ...
- 172. Factorial Trailing Zeroes
/**172. Factorial Trailing Zeroes *2016-6-4 by Mingyang* 首先别忘了什么是factorial,就是阶乘.那么很容易想到需要统计* (2,5)对的 ...
- leetcode python3 简单题172. Factorial Trailing Zeroes
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百七十二题 (1)题目 英文: Given an integer n, retu ...
- Leetcode 172 Factorial Trailing Zeroes
1.题目要求 Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be ...
- LeetCode(172) Factorial Trailing Zeroes
题目如下: Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be ...
- 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 ...
- 172 Factorial Trailing Zeroes(阶乘后的零)————附带详细思路和代码
文章目录 0 效果 1 题目 2 思路 3 代码 0 效果 1 题目 Given an integer n, return the number of trailing zeroes in n!. N ...
- 【leetcode❤python】Move Zeroes
#-*- coding: UTF-8 -*- #filter()函数可以对序列做过滤处理,就是说可以使用一个自定的函数过滤一个序列, #把序列的每一项传到自定义的过滤函数里处理,并返回结果做过滤.最终 ...
最新文章
- MAVEN项目环境搭建
- 微信小程序中显示空格
- 为什么要学jquery
- 简易listview与adapter实现列表,ArrayAdapter和BaseAdapter
- C++(17)--详解const
- 源码编译mysql5.5_源码编译安装MySQL5.5
- java jsp动作_Java中级—JSP九大内置对象和动作
- 创建查看mysql8.0数据库_创建和选择数据库
- mysql 汉字拼音怎么获得_mysql汉字拼音取法
- KNN算法(10折交叉验证)
- 联想S3机子密码设置
- 适合产品经理的桌面壁纸-分类神器
- 已解决-内部版本7601 此windows副本不是正版
- webpack打包处理字体文件
- linux 定时任务 数量 性能,Linux 性能测试与分析
- Python网络编程自动化(HCIA)
- 测试语文水平的软件,语文试卷质量分析
- CSP-2019day1题解报告
- Flutter中解决AndroidX包与Support包冲突问题
- 产品与解决方案的问题。