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的更多相关文章

  1. [LeetCode] 172. Factorial Trailing Zeroes 求阶乘末尾零的个数

    Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explan ...

  2. LeetCode 172. 阶乘后的零(Factorial Trailing Zeroes)

    172. 阶乘后的零 172. Factorial Trailing Zeroes 题目描述 给定一个整数 n,返回 n! 结果尾数中零的数量. LeetCode172. Factorial Trai ...

  3. Leetcode#172 Fractorial Trailing Zero

    原题地址 n!含有多少个因子10,则结尾有多少个0 10=2*5,而2的个数肯定比5多,所以n!含有多少个因子5,则结尾有多少个0 如何计算n!有多少个因子5呢? 比如n=13,则: n! = 13 ...

  4. LeetCode 172. Factorial Trailing Zeroes (阶乘末尾零的数量)

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

  5. Java实现 LeetCode 172 阶乘后的零

    172. 阶乘后的零 给定一个整数 n,返回 n! 结果尾数中零的数量. 示例 1: 输入: 3 输出: 0 解释: 3! = 6, 尾数中没有零. 示例 2: 输入: 5 输出: 1 解释: 5! ...

  6. 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 ...

  7. ✡ 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 ...

  8. Leetcode 172 Factorial Trailing Zeroes

    给定一个数n 求出n!的末尾0的个数. n!的末尾0产生的原因其实是n! = x * 10^m 如果能将n!是2和5相乘,那么只要统计n!约数5的个数. class Solution { public ...

  9. 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 ...

随机推荐

  1. css3 animation实现风车转动

    项目中经常有用到动画效果,比如Loading.风车转动等等.最简单的办法是使用gif,但是gif在半透明背景下有白边,体验不友好,好在现在可以使用css3的anmiation来实现动画效果,极大的提升 ...

  2. linux下安装安装pcre-8.32

    linux下安装安装pcre-8.32 ./configure --prefix=/usr/local/pcre 出现以下错误 configure: error: You need a C++ com ...

  3. ext.net与extjs的关系

    一.在客户端,ext.net中可以使用extjs的语法. 如发送ajax请求, Ext.Ajax.request({            url: 'Common/getNode',         ...

  4. ASP.NET Web API - ASP.NET MVC 4 系列

           Web API 项目是 Windows 通信接口(Windows Communication Foundation,WCF)团队及其用户激情下的产物,他们想与 HTTP 深度整合.WCF ...

  5. mysqlbinlog 导出日志

    1.找到日志所在的位置 ls 正好我需要的日志在000011这个二进制文件里,所以直接执行下面的语句: mysqlbinlog --no-defaults --start-datetime=" ...

  6. 【转】深入 Docker:容器和镜像

    在本专栏往期的 Flux7 系列教程 里,我们已经简单地探讨了 Docker 的基本操作.而在那篇教程中,我们一直是简单地将容器当成是"正在运行的镜像",并没有深入地区分镜像和容器 ...

  7. MySQL 使用笔记(一) 关联

    2016-12-16 一.当前未掌握总结: 目前MySQL中不会的内容: 1.临时表(变量表) 2.存储过程 3.游标 4.函数 二.关联 内联.左关联.右关联.外联 (一).标准sql语句中的关联及 ...

  8. os and shutil

    # os 模块 os.sep 可以取代操作系统特定的路径分隔符.windows下为 '\\'os.name 字符串指示你正在使用的平台.比如对于Windows,它是'nt',而对于Linux/Unix ...

  9. Zookeeper启动过程

    在上一篇,我们了解了zookeeper最基本的配置,也从中了解一些配置的作用,那么这篇文章中,我们将介绍Zookeeper的启动过程,我们在了解启动过程的时候还要回过头看看上一篇中各个配置参数在启动时 ...

  10. List的FindIndex和ForEach

    FindIndex和ForEach能接受一个delegate,用来定义查找规则太好用. 匿名函数,萌萌哒:Conditional("DEBUG")也是极好的. 读<C#本质论 ...