码迷,mamicode.com
首页 > 其他好文 > 详细

LightOJ 1138 二分

时间:2016-08-28 11:08:40      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

1138 - Trailing Zeroes (III)
Time Limit: 2 second(s) Memory Limit: 32 MB

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

Output for Sample Input

3

1

2

5

Case 1: 5

Case 2: 10

Case 3: impossible

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e5+10,M=4e6+10,inf=1e9+10;
int a[20]={5,25,125,625,3125,15625,78125,390625,1953125,9765625,48828125,244140625,1220703125};
int check(int x)
{
    int sum=0;
    for(int i=0;i<13;i++)
        sum+=x/a[i];
    return sum;
}
int main()
{
    int x,y,z,i,t;
    int T,cas=1;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&x);
        int st=0;
        int en=500000000;
        while(st<en)
        {
            int mid=(st+en)>>1;
            if(check(mid)>=x)
            en=mid;
            else
            st=mid+1;
        }
        printf("Case %d: ",cas++);
        if(check(st)==x)
        printf("%d\n",st);
        else
        printf("impossible\n");
    }
    return 0;
}

 

LightOJ 1138 二分

标签:

原文地址:http://www.cnblogs.com/jhz033/p/5814461.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!