当前位置:网站首页>阶乘末尾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;
}
}
边栏推荐
- Complete source code of mall applet project (wechat applet)
- After two years of graduation, I switched to software testing and got 12k+, and my dream of not taking the postgraduate entrance examination with a monthly salary of more than 10000 was realized
- 二叉树(北京邮电大学机试题)(DAY 85)
- [learning notes, dog learning C] string + memory function
- “满五唯一”和“满二唯一”是什么?有什么不同?
- Abbkine AbFluor 488 细胞凋亡检测试剂盒特点及实验建议
- Best practices of opentelemetry in service grid architecture
- 【flask】服务端获取客户端请求的文件
- Pytoch loss function summary
- OC-消息机制
猜你喜欢

Comprehensive care analysis lyriq Ruige battery safety design

win10/win11无损扩大C盘空间,跨盘合并C、E盘

Pytoch loss function summary

How big is the bandwidth of the Tiktok server for hundreds of millions of people to brush at the same time?

Yilingsi T35 FPGA drives LVDS display screen

How to use devaxpress WPF to create the first MVVM application in winui?

How many implementation postures of delay queue? Daily essential skills!

FactoryBean的getObject调用时机

Win10/win11 lossless expansion of C disk space, cross disk consolidation of C and e disks

带你了解什么是 Web3.0
随机推荐
“满五唯一”和“满二唯一”是什么?有什么不同?
自己梳理的LocalDateTime的工具类
【flask】服务端获取客户端请求的文件
Mysql: summary of common sub database and sub table schemes of Internet companies
Idea 中添加支持@Data 插件
$128million! IQM, a Finnish quantum computing company, was supported by the world fund
字节一面:TCP 和 UDP 可以使用同一个端口吗?
Bulk copy baby upload prompt garbled, how to solve?
快速排序及优化
Yilingsi T35 FPGA drives LVDS display screen
An error in the fourth edition of the red book?
带你了解什么是 Web3.0
优炫数据库集群如何唯一标识一条用户SQL
The EXE compiled by QT is started with administrator privileges
食物链(DAY 79)
docker 创建mysql 8.x容器,支持mac ,arm架构芯片
Baidu cloud face recognition
[flask] the server obtains the request header information of the client
shell awk
消息被拒MQ