Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in logarithmic time complexity.

(1)

class Solution {
public:
int trailingZeroes(int n) {
int ans = ;
for(long long i = ; n / i; i *= )
{
ans += n / i;
}
return ans;
}
};

(2)

class Solution {
public:
int trailingZeroes(int n) {
int ans = ;
while(n)
{
int t = n / ;
ans += t;
n = t;
}
return ans;
}
};

172. Factorial Trailing Zeroes -- 求n的阶乘末尾有几个0的更多相关文章

  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

    Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. Note: Your ...

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

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

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

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

  6. 172. Factorial Trailing Zeroes(阶乘中0的个数 数学题)

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

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

    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

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  9. Java [Leetcode 172]Factorial Trailing Zeroes

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

随机推荐

  1. wamp出现could not execute run action问题

    wamp出现could not execute run action问题     原文地址:http://blog.sina.com.cn/s/blog_4a60ba9c0100zzlr.html上午 ...

  2. json和jsonp的传输方式

    jsonp传输会解决跨域的问题 $.ajax({ async: false, /* url: "http://127.0.0.1:8080/2015020601/background/mea ...

  3. 在Spring中使用脚本

    Spring支持3中不同的脚本语言(看来支持地还挺多的嘛):JRuby.Groovy和BeanShell. 这三个都是java社区的脚本语言(反正到目前为止我一个都没用过,可见我有多挫). JRuby ...

  4. [SAP ABAP开发技术总结]数据引用(data references)、对象引用(object references)

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  5. Python入门-行和缩进

    学习Python与其他语言最大的区别就是,Python的代码块不使用大括号({})来控制类,函数以及其他逻辑判断.python最具特色的就是用缩进来写模块. 缩进的空白数量是可变的,但是所有代码块语句 ...

  6. Google's Open Source SLAM Library ---- Cartographer

    What is Cartographer? Google announce the open source release of Cartographer, a real-time simultane ...

  7. shell script针对参数已经有配置好变量名称

    /path/to/scriptname opt1 opt2 opt3 opt4 $ $ $ $ $ 这样够清楚了吧?运行的脚本档名为 $0 这个变量,第一个接的参数就是 $1 啊- 所以,只要我们在 ...

  8. [转]瓦的VPS后台kiwivm面板使用+安装AMH+装VPN

    参考网址:http://u-lis.com/archives/4159 ZC:网页图片保存于“百度云 OsSkill --> 全部文件 > 知识__来自网页 > 瓦 > 瓦_面 ...

  9. mysql 索引的原理

    1.考虑下面的情况,mysql> desc student;+----------+-------------+------+-----+---------+-------+| Field | ...

  10. Vsftpd服务的搭建

    安装vsftpd服务程序 yum install vsftpd -y Vsftpd的程序与配置文件: 主程序 /usr/sbin/vsftpd 用户禁止登陆列表 /etc/vsftpd/ftpuser ...