[LintCode] Trailing Zeroes 末尾零的个数
Write an algorithm which computes the number of trailing zeros in n factorial.
11! = 39916800, so the out should be 2
O(log N) time
LeetCode上的原题,请参见我之前的博客Factorial Trailing Zeroes。
解法一:
class Solution {
public:
// param n : description of n
// return: description of return
long long trailingZeros(long long n) {
long long res = ;
while (n > ) {
res += n / ;
n /= ;
}
return res;
}
};
解法二:
class Solution {
public:
// param n : description of n
// return: description of return
long long trailingZeros(long long n) {
return n == ? : n / + trailingZeros(n / );
}
};
[LintCode] Trailing Zeroes 末尾零的个数的更多相关文章
- 一步一步写算法(之n!中末尾零的个数统计)
原文:一步一步写算法(之n!中末尾零的个数统计) [ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 在很多面试的题目中,求n!结果中零的个数也是 ...
- [LeetCode] Factorial Trailing Zeroes 求阶乘末尾零的个数
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- [LeetCode] 172. Factorial Trailing Zeroes 求阶乘末尾零的个数
Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explan ...
- [CareerCup] 17.3 Factorial Trailing Zeros 求阶乘末尾零的个数
LeetCode上的原题,讲解请参见我之前的博客Factorial Trailing Zeroes. 解法一: int trailing_zeros(int n) { ; while (n) { re ...
- [LintCode] Move Zeroes 移动零
Given an array nums, write a function to move all 0's to the end of it while maintaining the relativ ...
- LightOj1028 - Trailing Zeroes (I)---求因子个数
题目链接:http://lightoj.com/volume_showproblem.php?problem=1028 题意:给你一个数 n (1<=n<=10^12), 然后我们可以把它 ...
- 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 ...
- Light oj 1138 - Trailing Zeroes (III) 【二分查找 && N!中末尾连续0的个数】
1138 - Trailing Zeroes (III) problem=1138"> problem=1138&language=english&type=pdf&q ...
- LeetCode 172. Factorial Trailing Zeroes (阶乘末尾零的数量)
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
随机推荐
- VMWARE修改CPUID
在cmd shell下执行wmic cpu get ProcessorId命令,可是查看机器的cpuID,但这个命令显示的只是2组ID,实际CPUID,有4组 通过更改虚拟机配置文件.vmx可是实现任 ...
- c++队列基本功能
#include<string>#include<assert.h>#include<iostream>typedef int status;#define OK ...
- C#设计模式之原型模式
原型模式:使用原型实例指定待创建对象的类型,并且通过复制这个原型来创建新的对象. 分析: 孙悟空:根据自己的形状复制(克隆)出多个身外身 软件开发:通过复制一个原型对象得到多个与原型对象一模一样的新对 ...
- java常见的问题
1. 接口与抽象类的区别? 抽象类:含有abstract修饰的class即为抽象类abstract类不能创建实例对象,不能有抽象的构造方法或抽象的静态方法,如果子类没有实现抽象父类中的所有 方法, ...
- C语言 遍历流程 变量生命周期
来自c程序设计 谭浩强 程序编译流程 运行c程序的步骤 在编好一个c程序后.怎样上机进行编译运行呢?一般要经过一下几个步骤: 上机输入和编辑源程序.通过键盘和计算机输入程序,如果发现有错误,要及时改正 ...
- HDU5988 Coding Contest(费用流)
2016青岛现场赛的一题,由于第一次走过不会产生影响,需要拆点,不过比赛时没想到,此外还有许多细节要注意,如要加eps,时间卡得较紧要注意细节优化等 #include <iostream> ...
- OpenCv图像裁剪指点区域_roi
两种方式Range和ROI #include <opencv2/opencv.hpp> using namespace std; using namespace cv; void test ...
- Win10商店东方财富网 UWP版更新,支持平板,PC,手机
东方财富股份有限公司 近日向Win10商店提交了东方财富网V4.1版,这次为广大Win10平台用户带来了期待已久的桌面版本,可谓是良心厂商,值得鼓励和支持.4.1主要更新: 1. 支持桌面Window ...
- `这个符号在mysql中的作用
` 是 MySQL 的转义符,避免和 mysql 的本身的关键字冲突,只要你不在列名.表名中使用 mysql 的保留字或中文,就不需要转义. 所有的数据库都有类似的设置,不过mysql用的是`而已.通 ...
- ubuntu14.04 安装 搜狗输入法
1.安装或者更新fcitx libssh2-1:sudo apt-get install fcitx libssh2-1; 2.搜索是否安装成功: dpkg -l | grep fcitx ; dp ...