Leetcode 172 Factorial Trailing Zeroes
给定一个数n 求出n!的末尾0的个数。
n!的末尾0产生的原因其实是n! = x * 10^m
如果能将n!是2和5相乘,那么只要统计n!约数5的个数.
class Solution {
public:
int trailingZeroes(int n) {
int ans = ;
for( ;n; ans+=n/,n/=);
return ans;
}
};
Leetcode 172 Factorial Trailing Zeroes的更多相关文章
- [LeetCode] 172. Factorial Trailing Zeroes 求阶乘末尾零的个数
Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explan ...
- LeetCode 172. Factorial Trailing Zeroes (阶乘末尾零的数量)
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- Java 计算N阶乘末尾0的个数-LeetCode 172 Factorial Trailing Zeroes
题目 Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in ...
- ✡ leetcode 172. Factorial Trailing Zeroes 阶乘中的结尾0个数--------- java
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- Java for LeetCode 172 Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- Java [Leetcode 172]Factorial Trailing Zeroes
题目描述: Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be ...
- leetcode 172. Factorial Trailing Zeroes(阶乘的末尾有多少个0)
数字的末尾为0实际上就是乘以了10,20.30.40其实本质上都是10,只不过是10的倍数.10只能通过2*5来获得,但是2的个数众多,用作判断不准确. 以20的阶乘为例子,造成末尾为0的数字其实就是 ...
- [LeetCode]172. Factorial Trailing Zeroes阶乘尾随0的个数
所有的0都是有2和45相乘得'到的,而在1-n中,2的个数是比5多的,所以找5的个数就行 但是不要忘了25中包含两个5,125中包含3个5,以此类推 所以在找完1-n中先找5,再找25,再找125.. ...
- LeetCode Day4——Factorial Trailing Zeroes
/* * Problem 172: Factorial Trailing Zeroes * Given an integer n, return the number of trailing zero ...
随机推荐
- deep learning
今天跑一个模型,程序都没变,就配置文件变了.但是总是很快就显示loss为nan. 检查配置文件还是不行,把其中loss改为0还是不行.最后搁置了一下,再回头对比一下电脑上的和服务器上的,发现一个配置文 ...
- swift webView 提出这样的要求你能忍吗?
提出的要求是:webView字体显示大小合适,里面会有大的图片,大的表格,不能按比例缩放,可以左右滑动查看. 首先,如果要满足上面的要求需要将webView放入scrollView中显示 scroll ...
- Block的copy和循环引用的问题
在实际开发中,发现使用Block有着比delegate和notification更简洁的优势.于是在目前的项目中大量的使用block. 在我的头文件我是这样声明使用block的. 我将block声明为 ...
- ListView和ScrollView冲突
当ListView放在ScrollView中的时候,无论你设置高度为 match_parent(填充父窗体)和wrap_content(包裹内容)都只显示一行,这是你把ListView放在Linear ...
- js完美转换阿拉伯数字为数字大写(原创)
啥都不说,直接上代码: //阿拉伯数字转换为简写汉字 function Arabia_To_SimplifiedChinese(Num) { for (i = Num.length - 1; i &g ...
- 自已实现的async 只实现了一部分功能
不得不说,人和人的技术确实有差距,同样的功能,其他人就是有办写写的更优雅性能更好 不论是C还是js 自已有功能但看着也比人家的丑好多. //最终效果 同async //目前实现了个人最常用的 seri ...
- nginx配置文件nginx.conf超详细讲解
#nginx进程,一般设置为和cpu核数一样worker_processes 4; #错误日志存放目录 error_log /data1/logs/er ...
- [JS]应用splice删除多元素时出现的坑
------------------------------------------------------------------------------------- 先看一个片段: var fr ...
- [Ng]Angular应用点概览
1. 使用模块化写法. var app = angular.module('myApp', []); app.controller('TextController', function($scop ...
- 更换光纤后路由器端口映射 -VPN相关
之前一直是ADSL的线路,使用路由器后,很简单就可以实现端口映射了!外网也可以随意连接,可是最近升级宽带更换了光纤后,发现怎么都不能正常工作了!在光纤猫里显示的IP居然是:10.0.*.*,查询到的外 ...