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

思路:

有几个零就是看能分解出几个5,所以用二分查找是否存在能分解出n个5的数

代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<iostream>
#include<algorithm>
#define INF 0x3f3f3f3f
#define ll long long
const int N=1e5+5;
const int MOD=1000;
const double C=0.57721566490153286060651209;
using namespace std; ll judge(int x){ //判断数x能分解出5的个数
ll res=0;
while(x){
res+=x/5;
x/=5;
}
return res;
} ll panduan(ll n){
ll l=0,r=5e8+1;
ll mid,res;
while(r>=l){
mid=(l+r)/2;
if(judge(mid)>=n){
res=mid;
r=mid-1;
}
else{
l=mid+1;
}
}
return res;
}
int main(){
int T,num=1;
ll ans,n;
ll mid,l,r;
scanf("%d",&T);
while(T--){
scanf("%lld",&n);
int ans=panduan(n);
if(judge(ans)==n){
printf("Case %d: %lld\n",num++,ans);
}
else{
printf("Case %d: impossible\n",num++);
}
}
return 0;
}

Trailing Zeroes (III) (二分)题解的更多相关文章

  1. 1138 - Trailing Zeroes (III) 二分

    1138 - Trailing Zeroes (III)   You task is to find minimal natural number N, so that N! contains exa ...

  2. Light oj 1138 - Trailing Zeroes (III) (二分)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N. 我们可以知 ...

  3. C - Trailing Zeroes (III) 二分

    You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in d ...

  4. Trailing Zeroes (III)(lightoj 二分好题)

    1138 - Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit:  ...

  5. light oj 1138 - Trailing Zeroes (III)【规律&&二分】

    1138 - Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit:  ...

  6. LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)

    http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS     M ...

  7. Light oj 1138 - Trailing Zeroes (III) 【二分查找好题】【 给出N!末尾有连续的Q个0,让你求最小的N】

    1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...

  8. Light oj 1138 - Trailing Zeroes (III) 【二分查找 &amp;&amp; N!中末尾连续0的个数】

    1138 - Trailing Zeroes (III) problem=1138"> problem=1138&language=english&type=pdf&q ...

  9. LightOJ Trailing Zeroes (III) 1138【二分搜索+阶乘分解】

    1138 - Trailing Zeroes (III) PDF (English) problem=1138" style="color:rgb(79,107,114)" ...

  10. Trailing Zeroes (III) -;lightoj 1138

    Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Y ...

随机推荐

  1. vue中给请求到的数据对象加属性问题

    今天发现了个很奇怪的问题,我在做一个:点击列表  使点中的列表项变色的功能,而且是多个大列表项,在每个大列表项里点击切换列表项的时候不影响其他大列表项的选项. 解决思路,因为这些大列表项是请求到的数据 ...

  2. Centos7网桥配置

    CentOS 的网桥虽然配置了很多次,不过总是记不住那几条,还是简单记录下,增加网桥可以通过brctl命令,但是为了简便快捷,直接生成配置文件即可 1.在/etc/sysconfig/network- ...

  3. 如何bitbucket上删除项目

    老外网页操作习惯不同,删除项目的按钮,我花了半天,突然瞟到delete,如下图(真他妈的隐蔽,记住这2017/3/7):

  4. Loadrunner解决启动浏览器后页面显示空白

    Loadrunner解决启动浏览器后页面显示空白 2018年5月20日,今天照常打开Loadrunner准备学习,在录制的时候却出现了一个问题,浏览器可以启动,但是程序页面缺是加载不出来,主要症状体现 ...

  5. 如何控制dedecms描述的长度?

    我们都知道调用dedecms的标题长度可以用titlelen='字符数',{dede:arclist titlelen='10'},表示标题长度为10个字符,也即是5个汉字.如果想要控制描述的调用长度 ...

  6. dedecms获取当前文章所在栏目URL

    我们知道dedecms有一个面包屑导航的调用函数,{dede:field name='position'/},这个样式是固定的,有时要个性化一些的话需要修改很多地方,那么织梦cms有没其他方法获取当前 ...

  7. pem转cer

    openssl x509 -inform pem -in fullchain.pem -outform der -out fullchain.cer

  8. SpringMVC学习笔记二第一个小的程序

    首先:我们要用springmvc来写一个helloworld的例子: 首先我们需要导入所需要的架包: /demo1/WebRoot/WEB-INF/lib/commons-logging-1.1.1. ...

  9. cocos代码研究(7)即时动作子类学习笔记

    理论部分 即时动作是会立即被执行的动作.他们没有持续时间动作(ActionInterval)的持续时间属性.继承自 FiniteTimeAction.被 CallFunc, FlipX, FlipY, ...

  10. Python: ValueError: too many values to unpack

    eg1: >>>a,b=(1,2,3) Traceback (most recent call last): File "<stdin>",line ...