求最小的N满足N!尾部0的数量为q.
直接用二分求了,注意0的情况,应该输出1.
#include <iostream>
#include <limits.h>
#include <cstdio>
using namespace std;
int q;
int main(){
while (scanf("%d", &q) == 1){
long long n = LLONG_MAX;
long long pre = n;
long long l = 0, r = n;
while (l <= r){
long long mid = (l + r) / 2;
long long t= mid;
long long tmpq = 0;
while (t && tmpq <= q){
tmpq += t / 5;
t /= 5;
}
if(tmpq == q){
pre = mid;
r--;
}else if(tmpq < q){
l = mid + 1;
}else{
r = mid -1;
}
}
if(q == 0)
printf("1\n");
else if(pre == n)
printf("No solution\n");
else
printf("%I64d\n",pre);
}
return 0;
}