当前位置:网站首页>Leetcode-阶乘函数后 K 个零
Leetcode-阶乘函数后 K 个零
2022-04-23 01:37:00 【程序猿不脱发2】
f(x) 是 x! 末尾是 0 的数量。回想一下 x! = 1 * 2 * 3 * … * x,且 0! = 1 。
例如, f(3) = 0 ,因为 3! = 6 的末尾没有 0 ;而 f(11) = 2 ,因为 11!= 39916800 末端有 2 个 0 。
给定 k,找出返回能满足 f(x) = k 的非负整数 x 的数量。
示例 1:
输入:k = 0
输出:5
解释:0!, 1!, 2!, 3!, 和 4! 均符合 k = 0 的条件。
示例 2:
输入:k = 5
输出:0
解释:没有匹配到这样的 x!,符合 k = 5 的条件。
示例 3:
输入: k = 3
输出: 5
java代码:
class Solution {
public int preimageSizeFZF(long K) {
long lo = K, hi = 10*K + 1;
while (lo < hi) {
long mi = lo + (hi - lo) / 2;
long zmi = zeta(mi);
if (zmi == K) return 5;
else if (zmi < K) lo = mi + 1;
else hi = mi;
}
return 0;
}
public long zeta(long x) {
if (x == 0) return 0;
return x/5 + zeta(x/5);
}
}
版权声明
本文为[程序猿不脱发2]所创,转载请带上原文链接,感谢
https://blog.csdn.net/kangbin825/article/details/124356360
边栏推荐
- [registration] tf54: engineer growth map and excellent R & D organization building
- 深入解析Linux下的磁盘缓存机制与SSD的写入放大问题
- Jerry's AI server [chapter]
- World reading day: 18 it books with Douban score above 9.0 are worth collecting
- Gbase 8s存储结构简介及空间管理
- Use Charles to grab app package
- Use yolov4 on colab
- 计蒜客:数独(DFS)
- 王子救公主(DFS)
- Google developer tool preserve log
猜你喜欢

Text justify, orientation, combine text attributes

数字藏品平台入驻 数字藏品平台开发 数字藏品SaaS平台

Basic knowledge of software testing (detailed version) collection of this article is enough

Use Charles to grab app package

42、使用mmrotate中k3det进行旋转目标检测,并进行mnn部署和ncnn部署

Prince saves Princess (DFS)

VSCODE + PHP Debug + 名字空间指引

DO447管理用户和团队的访问

Completely uninstall antidote 10? What if the antidote uninstall is not clean?

DFS parity pruning
随机推荐
Introduction à la structure de stockage de gbase 8S et à la gestion de l'espace
Slow response of analysis API
Analysis of uboot directory structure
计蒜客(踏青)(染色块问题的DFS和BFS解法)
12 years of testing predecessors give you some suggestions for learning software testing
Gbase 8s 并发控制之粒度锁介绍
Update description of the latest process engine flowable 6.7.2
GBase 8s查询处理和优化
Oracle database query lock table SQL script and delete lock information script (necessary for database development ETL and DBA)
UVC camera encapsulation class
GBASE 8s 并发控制之封锁操作
Abused "architect"!
Google developer tool preserve log
Introduction to Alibaba's super large-scale Flink cluster operation and maintenance system
Introduction to gbase 8s storage structure and space management
Linux系统下以RPM方式如何安装mysql-5.7.9
Gbase 8s query processing and optimization
Level 4 city area table xlsx, SQL file, domestic, provincial, county, street, township level 4 address in China (name, linkage ID, level, end level or not (1-yes))
引爆炸弹(DFS)
Redis implements distributed locks