给定一个数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的更多相关文章

  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 (阶乘末尾零的数量)

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

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

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

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

  6. Java [Leetcode 172]Factorial Trailing Zeroes

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

  7. leetcode 172. Factorial Trailing Zeroes(阶乘的末尾有多少个0)

    数字的末尾为0实际上就是乘以了10,20.30.40其实本质上都是10,只不过是10的倍数.10只能通过2*5来获得,但是2的个数众多,用作判断不准确. 以20的阶乘为例子,造成末尾为0的数字其实就是 ...

  8. [LeetCode]172. Factorial Trailing Zeroes阶乘尾随0的个数

    所有的0都是有2和45相乘得'到的,而在1-n中,2的个数是比5多的,所以找5的个数就行 但是不要忘了25中包含两个5,125中包含3个5,以此类推 所以在找完1-n中先找5,再找25,再找125.. ...

  9. LeetCode Day4——Factorial Trailing Zeroes

    /* * Problem 172: Factorial Trailing Zeroes * Given an integer n, return the number of trailing zero ...

随机推荐

  1. HTML5和CSS3基础教程(第8版)-读书笔记(4)

    第16章 表单 表单有两个基本组成部分:访问者在页面上可以看见并填写的控件.标签和按钮的集合:以及用于获取信息并将其转化为可以读取或计算的格式的处理脚本. 基本的表单字段类型包括文本框.单选按钮.复选 ...

  2. JS事件冒泡

    JavaSciprt事件中有两个很重要的特性:事件冒泡以及目标元素. 事件冒泡: 当一个元素上的事件被触发的时候,比如说鼠标点击了一个按钮,同样的事件将会在那个元素的所有祖先元素中被触发.这 一过程被 ...

  3. calc()问题

    什么是calc()? 学习calc()之前,我们有必要先知道calc()是什么?只有知道了他是个什么东东?在实际运用中更好的使用他. calc() 从字面我们可以把他理解为一个函数function.其 ...

  4. UE简单操作

    一:UE恢复默认配置      1.开始--运行-- “%APPDATA%” 回车 .      2. 找到并打开 IDMComp 文件夹.将文件夹“UltraEdit”整个给删除.      3.重 ...

  5. Windows通用应用开发手记-Behavior SDK概述

    随着Visual Studio 2013的发布,New Behavior SDK也一起出现了.和Expression Blend SDK相似,包括各种内置行为(behavior和action),可以用 ...

  6. yield学习续:yield return迭代块在Unity3D中的应用——协程

    必读好文推荐: Unity协程(Coroutine)原理深入剖析 Unity协程(Coroutine)原理深入剖析再续 上面的文章说得太透彻,所以这里就记一下自己的学习笔记了. 首先要说明的是,协程并 ...

  7. 利用Java自带的MD5加密

    package test.md5; import java.security.MessageDigest; public class MD5Util { public final static Str ...

  8. 【洛谷P3398】仓鼠找sugar

    画个图就能多少看出些规律 证明借鉴一下大牛的题解: 设从A到B,经过的深度最小的点为X 同理,C,D的为Y 题目是一个点从A出发到B 一个从C出发到D 那么从A到B可以分解成 先从A到X 再从X到B. ...

  9. 天气预报数据API

    http://www.weather.com.cn/data/cityinfo/101010100.html//过期: http://api.36wu.com/Weather/GetMoreWeath ...

  10. [转]Oracle数据泵的使用

    使用数据泵导出数据 1.连接Oracle数据库SQL> conn / as sysdba已连接. 2.创建一个操作目录SQL> create directory dump_dir as ' ...