leetcode 172
172. Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
计算出n!中尾部0的个数。1*2*3*......*n中0的个数由2和5的对数决定,由于因子5的个数小于因子2的个数,所以只需求出因子5 的个数即为尾部0的个数。
n/5可以求得能被5整除数的个数;
但25中存在两个因子,125中存在三个因子,依次类推。
所以在求因子5的时候应该考虑到。
代码如下:
class Solution {
public:
int trailingZeroes(int n) {
int count = ;
while(n)
{
count += n/;
n /= ;
}
return count;
}
};
leetcode 172的更多相关文章
- [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)
172. 阶乘后的零 172. Factorial Trailing Zeroes 题目描述 给定一个整数 n,返回 n! 结果尾数中零的数量. LeetCode172. Factorial Trai ...
- Leetcode#172 Fractorial Trailing Zero
原题地址 n!含有多少个因子10,则结尾有多少个0 10=2*5,而2的个数肯定比5多,所以n!含有多少个因子5,则结尾有多少个0 如何计算n!有多少个因子5呢? 比如n=13,则: n! = 13 ...
- 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 阶乘后的零
172. 阶乘后的零 给定一个整数 n,返回 n! 结果尾数中零的数量. 示例 1: 输入: 3 输出: 0 解释: 3! = 6, 尾数中没有零. 示例 2: 输入: 5 输出: 1 解释: 5! ...
- 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 ...
- Leetcode 172 Factorial Trailing Zeroes
给定一个数n 求出n!的末尾0的个数. n!的末尾0产生的原因其实是n! = x * 10^m 如果能将n!是2和5相乘,那么只要统计n!约数5的个数. class Solution { public ...
- 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 ...
随机推荐
- [Thinking in Java]这些必须先了解
2.基本概念和认识 2.1 Java引用 Java中一切皆是对象,一切对象实例的标识符号(对象名称)都只是对象的引用. 2.2 对象的创建 通过new关键字创建,但是要注意基础类型和String类型的 ...
- Linux环境下段错误的产生原因及调试方法小结(转)
最近在Linux环境下做C语言项目,由于是在一个原有项目基础之上进行二次开发,而且 项目工程庞大复杂,出现了不少问题,其中遇到最多.花费时间最长的问题就是著名的“段错误”(Segmentation F ...
- phpMyAdmin如何设置float小数点
在长度/值设置 5,2就行了哈
- Python之路,day11-Python基础
回顾:进程一个程序需要运行所需的资源的集合每个进程数据是独立的每个进程里至少有一个线程进程里可以有多个线程线程数据是共享的一个进程的多个线 6程可以充分利用多核cpumultiprocessing p ...
- sql查询语句
//查询表的字段名和字段类型select column_name,data_type from information_schema.columns where table_name = '表名' / ...
- _IntfClear报错问题
delphi对象在释放时会清除对象相关接口.如果开发人员在这之前已经将接口对应的对象释放掉,那么当清除到该接口时经常会报访问内存错误,如下图
- VS2012 InstallShield2013LimitedEdition激活
VS2012 InstallShield2013LimitedEdition激活 在实际开发工作中由于升级操作系统后,不知何种原因,导致 InstallShield2013LimitedEdition ...
- 使用PowerDesigner把oom设计图导出jpg格式的图片
1: 按住Shift键点击鼠标选择要导出的对象,必须先选择. 2: 选择Edit—>Export Image 到出你需要的格式,如下图
- linux新增用户并增加sudo权限
创建用户.设置密码: useradd testuser 创建用户testuserpasswd testuser 给已创建的用户testuser设置密码 增加sudo权限: #vi /etc/sudoe ...
- R语言-数据结构
1.向量 向量是用来存储数值型.字符型或逻辑性数据的一维数组,用函数c()创建向量 a <- c(1,2,5,6,4) b <- c("one","two&q ...