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
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.
Output
For each case, print the case number and N. If no solution is found then print 'impossible'.
Sample Input
3
1
2
5
Sample Output
Case 1: 5
Case 2: 10
Input
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.
Output
For each case, print the case number and N. If no solution is found then print 'impossible'.
Sample Input
3
1
2
5
Sample Output
Case 1: 5
Case 2: 10
Case 3: impossible
题目:给出N的阶乘最后0的个数求N。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f3f3f
#define maxn 200010
#define root 1,n,1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mod 10007
using namespace std;
ll sum(ll x){
ll k=5,ans=0;
while(x>=k){
ans+=x/k;
k*=5;
}
return ans;
}
int main(){
int t;scanf("%d",&t);
int test=0;
while(t--){
ll n;scanf("%lld",&n);
ll l=0,r=inf;
while(l<r){
ll mid=(l+r)/2;
if(sum(mid)<n) l=mid+1;
else r=mid;
}
if(sum(l)!=n)printf("Case %d: impossible\n",++test);
else
printf("Case %d: %lld\n",++test,l);
}
}