哈哈哈哈,虽然我不会做,但是我把答案猜出来了呀,贼开心。。
class Solution {
public:
/**
* @param K: an integer
* @return: how many non-negative integers x have the property that f(x) = K
*/
int fun(long long x) //返回x!后面零的个数
{
int count=0;
while(x)
{
count+=x/5;
x/=5;
}
return count;
}
int preimageSizeFZF(int K)
{
// Write your code here
long long l=1,r=K*5L+1; //就是这个参数,我猜的!!!!
int ans=0;
while(l<=r)
{
long long m=l+(r-l)/2;
int tmp = fun(m);
if(tmp == K)
{
ans=m;
break;
}
else if(tmp<K) l=m+1;
else r=m-1;
}
if(!ans) return 0;
return 5;
}
};