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. CSS初体验

    经过学习,我对css有了初步的认识.css是层叠样式表(Cascading Style Sheets的缩写,它用于HTML元素的显示形式,是W3C推出的格式化的标准技术.CSS现在已经被大多数浏览器所 ...

  2. 解释器模式(Interpreter Pattern)

    定义:给定一种语言,定义他的文法的一种表示,并定义一个解释器,该解释器使用该表示来解释语言中句子. 抽象解释器:声明一个所有具体表达式都要实现的抽象接口(或者抽象类),接口中主要是一个interpre ...

  3. js 防止页面后退的方法

    //防止页面后退 history.pushState(null, null, document.URL); window.addEventListener('popstate', function ( ...

  4. Entity Framework 摘记

    1.设置隔离级别 var transactionOptions = new System.Transactions.TransactionOptions(); transactionOptions.I ...

  5. Zookeeper基本配置

    前面两篇文章介绍了Zookeeper是什么和可以干什么,那么接下来我们就实际的接触一下Zookeeper这个东西,看看具体如何使用,有个大体的感受,后面再描述某些地方的时候也能在大脑中有具体的印象.本 ...

  6. DSP中.gel文件的作用

    GEL是CCS提供的一种解释语言,使用该语言写出的GEL,函数具有两在功能,一是配置CCS工作环境,二是直接访问目标处理器DSP(包括DSP软/硬仿真器).用户可以使用GEL函数完成类似于宏操作的自动 ...

  7. Svg path画线(不管是直线还是曲线)在一定情况下线条的宽度不一的情况(记录)

    在项目中涉及到svg: 使用path划线实现图表功能. 记录在实现的过程中发现的问题:path在小像素的情况下画出的线条宽度不一样.这是为什么呢? 以下是我做的猜想: 可以看图 在宽度给的很足的时候没 ...

  8. Linux MySql install and use with c++

    1.安装mysql客户端 用命令: yum install -y mysql-server mysql mysql-devel 此命令包含了安装客户端和服务器 2.访问myslq 在命令行输入: my ...

  9. SQL:安装多个实例,修改实例端口号,和IP加端口号连接实例

    sql server 安装第一个实例,默认实例的端口是1433, 一个库中如果有多个实例,从第二个实例开始的端口是动态端口,需要的话,自己手工指定为静态端口,如指定第二个实例为1434 或着随意一个如 ...

  10. rails下react的demo

    gemfile gem 'react-rails' gen一下 react:install 创建组件 react:component MyComponent name:string age:int v ...