POJ 1401 Factorial 解题报告
来源:互联网 发布:淘宝虚拟试衣间还有吗 编辑:程序博客网 时间:2024/06/05 02:17
以下是算法的直观解释。
假设求60!的结果后面有几个0。
由《编程之美》可知其实是求1,2,3……60中共有几个5的因子,如,5有一个,10有两个,……一起加起来即得到结果。但是如果一个一个这样计算下去,会超时的。
其实还有更简单的计算方法。
我们知道,在1->60的数中,以下的数可以被5整除:
5,10,15,20,25,30,35,40,45,50,55,60
共60/5 = 12(个)。
其中,
25,50可以被25整除,即25和50可以贡献两个5的因子。
即其中可以贡献2个5的因子的个数为60/25 = 2(个)。
贡献3个5的因子的没有了,因为60/125 = 0。
所以共有12 + 2 = 14 (个)5的因子。(即1 * 10 + 2 * 2)
- POJ 1401 Factorial 解题报告
- POJ 1401 解题报告
- LeetCode-Factorial Trailing Zeroes-解题报告
- 【LeetCode】Factorial Trailing Zeroes 解题报告
- [leetcode] 172. Factorial Trailing Zeroes 解题报告
- [Leetcode] 172. Factorial Trailing Zeroes 解题报告
- poj解题报告——1401
- poj 1401 Factorial
- POJ 1401 Factorial
- POJ 1401 Factorial
- poj 1401 Factorial
- poj 1401 Factorial
- poj 1401 Factorial
- poj 1401 Factorial
- 1401 poj Factorial
- POJ 1401 Factorial
- Poj 1401 Factorial
- poj 1401 Factorial
- 设计模式二,Proxy,State,Adapter,Template Method
- 可多行显示和输入的TextBox(java)
- grub rescue 的修复(Error:no such device)!
- 工厂设计模式
- 工厂设计模式
- POJ 1401 Factorial 解题报告
- 再建 oracle em
- 想跳槽时看看
- dfsdf
- ubuntu下rar中文名乱码问题
- 枚举
- 评语
- 在线人员控制代码
- Linux下Java编程