没看懂题目的意思吧,cv以后有时间理解一下
package com.算法专练.力扣.阶乘函数后K个零;
/**
* @author xnl
* @Description:
* @date: 2022/8/28 22:00
*/
public class Solution {
public static void main(String[] args) {
Solution solution = new Solution();
System.out.println(solution.preimageSizeFZF(5));
}
public int preimageSizeFZF(int k) {
return (int) (help(k + 1) - help(k));
}
private long help(int k){
long r = 5L * k;
long l = 0;
while (l <= r){
long mid = (r + l) >> 1;
if (zeta(mid) < k){
l = mid + 1;
} else {
r = mid - 1;
}
}
return r + 1;
}
private long zeta(long x){
long res = 0;
while (x != 0){
res += x / 5;
x = x / 5;
}
return res;
}
}