题意:http://www.lightoj.com/volume_showproblem.php?problem=1138

因为末尾有几个0   那么必定和5的个数有关 

在n的阶乘中  求5的个数  在大数的范围下 二分来完成

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include<vector>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define N 1006
LL q(LL x)
{///n的阶乘中  有几个5
    LL ans=0;
    while(x)
    {
        ans+=x/5;
        x=x/5;
    }
    return ans;
}
int main()
{
    int T,t=1;
    scanf("%d",&T);
    while(T--)
    {
        LL n;
        scanf("%lld",&n);
        LL l=1,r=INF;
        while(l<r)
        {
            LL mid=(r+l)/2;
            if(q(mid)>=n)
                r=mid;
            else l=mid+1;
        }
        if(q(l)!=n) printf("Case %d: impossible\n",t++);
        else
        printf("Case %d: %d\n",t++,l);
    }
    return 0;
}

如果查一个数末尾有多少个0  只需要查找有多少个2以及5  取最小值 就是

 

posted on 2017-10-23 17:00  云胡不喜。  阅读(93)  评论(0编辑  收藏  举报