当前位置:网站首页>阶乘末尾0的数量
阶乘末尾0的数量
2022-07-27 01:35:00 【斯沃福德】

思路:
题目不是算n!阶乘的结果,而是算阶乘的结果末尾有几个0 !


Java实现:
public class Solution {
public long thenumberof0 (long n) {
//结果为0的个数只与2与5的个数有关,
//每一次2*5就能产生一个0。因为2的个数肯定要大于5的个数,
//所以只要关注5的个数就可以了
if(n==0){
return 0;
}
long r=0;
long i=5;
while(i<=n){
r=r+n/i;// 用n除以5、5^2、5^3
i=i*5;
}
return r;
}
}
边栏推荐
- 将幕布文章OPML转换为Markdown的方法
- Boom 3D new 2022 audio enhancement app
- 图解用户登录验证流程,写得太好了!
- Zhang Ping, Alibaba cloud Solution Architect: system construction of cloud native digital safety production
- 带你了解什么是 Web3.0
- 30分钟彻底弄懂 synchronized 锁升级过程
- Bulk copy baby upload prompt garbled, how to solve?
- Worth more than 100 million! The 86 version of "red boy" refuses to be a Daocheng Xueba. He is already a doctor of the Chinese Academy of Sciences and has 52 companies under his name
- 代码审查金字塔
- 快速排序及优化
猜你喜欢

记录一次,php程序访问系统文件访问错误的问题

Yilingsi T35 FPGA drives LVDS display screen

图解 SQL,这也太形象了吧!

30分钟彻底弄懂 synchronized 锁升级过程
![[learning notes, dog learning C] string + memory function](/img/53/86e529dcc8a5a6b682e9485e7c152a.png)
[learning notes, dog learning C] string + memory function

OpenTelemetry 在服务网格架构下的最佳实践

Annotation summary of differences between @autowired and @resource

IDEA 连接数据库查询数据后控制台表头中文乱码的解决方法

Plato Farm全新玩法,套利ePLATO稳获超高收益

How big is the bandwidth of the Tiktok server for hundreds of millions of people to brush at the same time?
随机推荐
浅浅梳理一下双轴快排(DualPivotQuickSort)
Win10/win11 lossless expansion of C disk space, cross disk consolidation of C and e disks
impala 执行计划详解
Worthington木瓜蛋白酶解离系统解决方案
cocos小游戏实战-05-NPC与角色攻击逻辑
Byte side: can TCP and UDP use the same port?
spark学习笔记(五)——sparkcore核心编程-RDD转换算子
be based on. NETCORE development blog project starblog - (16) some new functions (monitoring / statistics / configuration / initialization)
Zhang Ping, Alibaba cloud Solution Architect: system construction of cloud native digital safety production
Worthington果胶酶的特性及测定方案
OC-消息机制
Hcip 13th day notes
30 minutes to thoroughly understand the synchronized lock upgrade process
IDEA 连接数据库查询数据后控制台表头中文乱码的解决方法
记录一次,php程序访问系统文件访问错误的问题
[从零开始学习FPGA编程-54]:高阶篇 - 基于IP核的FPGA开发-PLL锁相环IP核的原理与配置(Altera)
Worthington果胶酶的特性及测定方案
DNS记录类型及相关名词解释
食物链(DAY 79)
HCIP第十三天笔记