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
Case 3: impossible
/*
输入一个数,表示阶乘值末尾0的个数,求满足条件的最小数。
阶乘的规律:从2开始(包括2)从右到左第一位必定是2的倍数
(不包含2),所以这些数乘5必定是0。1 ~ 4 没有0、5 ~ 9有
1个零、10 ~ 14 有2个零。15 ~ 19有3个零。所以看出规律,每
出现一次5就会增加一个0;
*/
#include<stdio.h>
typedef long long ll;
ll judge(ll x)
{
ll cnt = 0;
while (x)
{
cnt += x / 5;
x /= 5;
}
return cnt;
} //这里是判断一个数是
//5的多少倍
int main()
{
int n, kase = 1;
scanf ("%d", &n);
while (n --)
{
int Q;
scanf ("%d", &Q);
printf("Case %d: ", kase++);
ll l = 0, r = 1e12, mid, ans;
while (l <= r)
{
mid = (l + r) / 2;
if (judge(mid) >= Q)
{
ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
if (judge(ans) == Q) printf ("%d\n", ans);
else printf ("impossible\n");
}
return 0;
}