当前位置:网站首页>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
边栏推荐
- Soatest preliminary understanding
- Introduction to gbase 8s checkpoint
- Gbase 8s 共享内存段删除
- 再谈被动安全 教你看懂中保研碰撞测试的评级报告
- gin框架的学习--golang
- iTextSharp 页面设置
- Planning garlic guest (outing) (DFS and BFS solution of dyeing block problem)
- Introduction to Alibaba's super large-scale Flink cluster operation and maintenance system
- GBase 8t索引
- Is the stable currency a super opportunity to accelerate the death of the public chain or replace BTC?
猜你喜欢

Google developer tool preserve log

Learning of gin framework -- golang
![Error: permissionerror: [winerror 32] this file is in use by another program and cannot be accessed by the process. Solution of](/img/eb/9031f00e41666941219974ea2e2274.png)
Error: permissionerror: [winerror 32] this file is in use by another program and cannot be accessed by the process. Solution of "+ file path"

王子救公主(DFS)

Small example of gin - get request 1-handle handles get requests

Chapter 9 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of exercises for users to establish their own data types

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

Slow response of analysis API

gin--hello

Realize the function of progress bar through layerdrawable
随机推荐
GBASE 8s分片表管理操作
Jerry's AI server [chapter]
Rotation slice
Custom numeric input control
科技云报道:云计算进入“下半场”,国产云的出路在哪儿?
What kind of project is suitable for automated testing?
2n皇后问题
天梯赛L2-6 树的遍历
计蒜客:方程的解数
Find number (DFS)
Introduction to gbase8s SQL Engine framework
第六章 使用 matplotlib 绘制热力图
Learning of gin framework -- golang
NR polar code VII - SCL (successful cancellation list coding)
World reading day: 18 it books with Douban score above 9.0 are worth collecting
GBase8s SQL 引擎框架简介
The most understandable life cycle of dependency injection
Jerry's CPU performance test [chapter]
Gbase 8s query processing and optimization
Linux系统下以RPM方式如何安装mysql-5.7.9