https://cn.vjudge.net/contest/173312#problem/C
You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in decimal notation. As you know N! = 1*2*...*N. For example, 5! = 120, 120 contains one zero on the trail.
Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case contains an integer Q (1 ≤ Q ≤ 108) in a line.
For each case, print the case number and N. If no solution is found then print 'impossible'.
3
1
2
5
Case 1: 5
Case 2: 10
Case 3: impossible
代码:
#include<cstdio>
#include<algorithm>
#define N 0x7fffffff
using namespace std;
int judge(int n)
{
int t=0;
while(n){
t+=n/5;
n/=5;
}
return t;
}
int main()
{
int T,x=1;
scanf("%d",&T);
while(T--){
int n,left=0,right, mid;
right=N;
scanf("%d",&n);
while(left<=right){
mid=(left+right)/2;
if(judge(mid)>=n){
right=mid-1;
}
else {
left=mid+1;
}
}
if(judge(left)==n) printf("Case %d: %d\n",x,left);
else printf("Case %d: impossible\n",x);
x++;
}
}