C

来源:互联网 发布:java 设置时区 编辑:程序博客网 时间:2024/06/16 17:19

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

注意:数据一定要足够大,否则,你懂得。。。。


#include <iostream>#include <cstdio>int app(long long int n){long long  ans=0;while(n>0){ans+=n/5;n/=5;}return ans;}int main(){      long long int t,w;    scanf("%lld",&t);    w=t;    while(t--)    {    long long int q,l,r,mid;    scanf("%lld",&q);    l=1;    r=2100000000;    long long sum=0;    while(l<=r)    {    mid=(l+r)/2;    if(app(mid)==q)    {    sum=mid;    r=mid-1;}       elseif(app(mid)>q)    {    r=mid-1;}else     {    l=mid+1;}    }if(sum>0)printf("Case %lld: %lld\n",w-t,sum);else printf("Case %lld: impossible\n",w-t);}return 0;}