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: impossibl
题解:5! 5*1 1 1+0=1 0
10! 5*2 1 1+1=2 00
15! 5*3 1 1+2=3 000
20! 5*4 1 1+3=4 0000
25! 5*5 2 2+4=6 000000
......
#include<cstdio>
#include<iostream>
using namespace std;
int solve(int a)
{
int r=0;
while(a)
{
r+=a/5;
a/=5;
}
return r;
}
int main()
{
int n,m;
int a[10000];a[1]=5;
int i,j,k;
while(scanf("%d",&i)!=EOF)
{
for(j=0;j<i;j++)
{
scanf("%d",&n);
int l=0,r=500000000,mid;
while(l<=r)
{
mid=(l+r)/2;
if(solve(mid)>n)
{
r=mid-1;
}
else
{
l=mid+1;
}
}
r=r-r%5;
if(solve(r)==n)
{
printf("Case %d: %d\n",j+1,r);
}
else
{
printf("Case %d: impossible\n",j+1);
}
}
}
return 0;
}