当前位置:网站首页>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
边栏推荐
- Garlic customer: equilateral triangle (DFS)
- Itextsharp infrastructure
- 2n queen problem
- [course summary] Hello harmonyos series of courses, take you to zero foundation introduction
- Custom numeric input control
- 最新流程引擎 flowable 6.7.2 更新说明
- Itextsharp page setup
- GBase 8t索引
- GBASE 8s 共享内存缓冲池介绍
- 全排列(DFS和next_permutation解法)
猜你喜欢
Cai Guoqiang's fireworks NFT debut is as wonderful as fireworks during the day
无关联进程间通信 —— 命名管道的创建和使用
计蒜客:方程的解数
Use Charles to grab app package
Completely uninstall antidote 10? What if the antidote uninstall is not clean?
The most understandable life cycle of dependency injection
(product resources) mingdeyang ad8488 module high performance digital X-ray FMC interface 128 analog channel high-speed ADC chip
世界读书日:18本豆瓣评分9.0以上的IT书值得收藏
In the second half of the smart watch, opportunities and challenges coexist
DO447管理用户和团队的访问
随机推荐
Software maintenance exercises
Gbase 8s group by function introduction
数字藏品平台入驻 数字藏品平台开发 数字藏品SaaS平台
After ten years of testing experience, I have sorted out the most suitable software testing learning guide for you
Google developer tool preserve log
. net (c) MySQL conn.open() reports an error: solution to SSL connection error
ai2022新功能,illustrator 2022 新功能介绍
Itextsharp page setup
Instructions for Jerry's reset IO maintenance level [chapter]
王子救公主(DFS)
Unity combines itextsharp to generate PDF preparation DLL
Modify array (and search set)
[蓝桥杯][2019年第十届真题]外卖店优先级
VRF in Mina
无关联进程间通信 —— 命名管道的创建和使用
gin -get请求的小示例2-Handle处理post请求
计蒜客:等边三角形(DFS)
Soatest preliminary understanding
Good test data management, in the end how to do?
Error: permissionerror: [winerror 32] this file is in use by another program and cannot be accessed by the process. Solution of "+ file path"