LintCode 2. 尾部的零
来源:互联网 发布:淘宝网怎样修改评价 编辑:程序博客网 时间:2024/05/18 14:24
这道题,分析如下,1到n的阶乘末尾的0数有多少个,只需要统计出n分别除以5,25,125...等5的整数次幂即可,然后相加就可得到n末尾包含的0的个数。每次5出现首先2,4都比5小,所以对于新出现的5的整数次幂的倍数时,前面肯定已经存在了足够的2使得2*5=10,从而在末尾产生新的0。
我的实现过程如下:
class Solution {public: /* * @param n: A long integer * @return: An integer, denote the number of trailing zeros in n! */ long long trailingZeros(long long n) { // write your code here, try to do it without arithmetic operators. long long sum=0; while(n!=0) { sum+=n/5; n=n/5; } return sum; }};
阅读全文
0 0
- LintCode 2.尾部的零
- LintCode 2. 尾部的零
- Lintcode 2. 尾部的零
- LintCode 尾部的零
- lintcode ---- 尾部的零
- LintCode : 尾部的零
- Lintcode 尾部的零
- LintCode:尾部的零
- Lintcode:尾部的零
- Lintcode 尾部零的个数
- LintCode 2 尾部的零
- LintCode Python 尾部的零
- 【LintCode】2、尾部的零
- [Lintcode] #2 尾部的零
- LintCode-(2)尾部的零
- Lintcode 2: 尾部的零
- lintcode 2:尾部的零
- LintCode Trailing Zeros 尾部的零
- 1018. 锤子剪刀布 (20)
- 转载:Spring Boot (十一):Spring boot中mongodb的使用
- 通过cmd命令查看某个端口的进程pid和并关闭该进程的操作
- [DesignPattern]CompoundPattern
- java 网络编程三要素之协议(UDP协议):
- LintCode 2. 尾部的零
- MySQL 5.6.17 版本发布及下载地址(mysql-5.6.17-winx64.zip)
- java功能jsp实战
- 插值多项式例子
- HDU 1114 Piggy-Bank
- 使用QStyle 高端定制弹出菜单 QPushButton源码剖析(一)
- python---- Hello World
- Unity摄像机跟随Player
- PAT乙级 1002 写出这个数