zstu Problem B: Suffix Zeroes(二分)

Problem B: Suffix Zeroes
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 723 Solved: 32

Description

这个游戏超休闲的~。现在你需要找一个自然数n,你找的自然数需要满足n!的末尾恰好有k个0(当然我们都是十进制下的数,n! = 123*…*n)。比如:5!= 120,尾部恰好有一个0。

Input

先输入T,代表有T组数据(T ≤10000)
接下来的T行每一行都包括一个数字k(1≤k≤108)。具体含义请见题意。

Output

如果能找到这样的数,请输出满足条件的最小的自然数n,如果不存在这样的自然数,请输出impossible。

Sample Input

2
1
5

Sample Output

Case 1: 5
Case 2: impossible

求末尾0的个数 每当有一个2*5的时候末尾就会有一个0 转化为求2,5的因子数 由于2的因子数较多直接求5的因子数即可。
在 5,1e9 之间二分找答案 先将 5, 5^2 , 打印到一个表中 ,直接将二分的数除这个表得到的就是末尾0的个数 当找到的数的时候就返回答案。
(代码还不能查看 先不贴了)


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<queue>
#define fi first
#define se second
#define FOR(a) for(int i=0;i<a;i++)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" !!! "<<b<<endl;
#define show3(a,b,c) cout<<a<<" !!! "<<b<<" !!! "<<c<<endl;
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<P, int> LP;
const ll inf = 1e8+10;
const ll mod = 998244353;
const int N=1005;
 
 
int a[N],po[100];
int n,m,x,y,s,t,cnt;
 
 
 
int pre(int x)
{
    int sum=0;
    for(int i=0;i<cnt;i++)
        sum+=x/po[i];
    return sum;
}
 
 
int main()
{
    po[0]=5;
    cnt=1;
    for(int i=1;po[i-1]*5ll<1e9;i++)
    {
        po[i]=po[i-1]*5;
        cnt++;
    }
    scanf("%d",&t);
    while(t--)
    {
        cin>>n;
        int l=5,r=1e9;
        int ans=-1;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            int ct=pre(mid);
            if(ct>n) r=mid-1;
            else if(ct==n)
            {
                ans=mid;
                r=mid-1;
            }
            else l=mid+1;
        }
        if(ans==-1) printf("Case %d: impossible\n",++s);
        else printf("Case %d: %d\n",++s,ans);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值