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

其实我特别反感这种思维题目,感觉没别的方法,没什么意思,只能这样写,还有就是我太菜了(这才是原罪)

思路::有几个0出现关键就看2和5的个数,因为是阶乘,都是乘法运算,所有要将没一个数拆开,看看他包括几个2或者几个5,,比如,10  可以分为2和5,所以只有1个5,而

25可以分为5和5 所以有两个5。。。。。在一组数中,二的数目一定比5 多吗,所以直接找5 的个数就可以啦!

记得设置为long long

AC代码:

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll sum(ll x){
ll ans=;
while(x)
{
ans+=x/;
x=x/;
}
return ans;
} int main()
{
int t;
scanf("%d",&t);
for(int i=;i<=t;i++)
{
ll n;
scanf("%lld",&n);
ll left=,right=,ans=,mid;
while(left<=right)
{
mid=(left+right)/;
if(sum(mid)==n){
ans=mid;
right=mid-;
}//找到了不一定是最小的比如11和10,阶乘都可以产生2个0
else if(sum(mid)>n){
right=mid-;
}
else {
left=mid+;
}
} if(ans>)
printf("Case %d: %lld\n",i,ans);
else
{
printf("Case %d: impossible\n",i);
}
}
return ;
}

C - 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. Trailing Zeroes (III)(lightoj 二分好题)

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

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

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

  5. 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 ...

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

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

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

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

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

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

  9. Trailing Zeroes (III) -;lightoj 1138

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

随机推荐

  1. CF1327C Game with Chips 题解

    原题链接 简要题意: 每个点有起始目标和终点(二维).要求每次将所有点向一个方向移动一次(四方向,若出界则不变),使得每个点均 经过 其终点. 本题只要抓住本质,瞬间得解. 你会发现,如果要求每个点最 ...

  2. effective-java学习笔记---使用标记接口定义类型40

    标记接口(marker interface),不包含方法声明,只是指定(或“标记”)一个类实现了具有某些属性的接口. 例如,考虑 Serializable 接口.通过实现这个接口,一个类表明它的实例可 ...

  3. 使用VS开始一个新项目配置外部库的新手总结

    在使用VS做一个项目的时候,往往会需要使用各种各样的库,一般一个标准的外部库目录大体结构为: VS在配置这些库的时候有多种可行方法,但是不同的方法对于项目后续的管理和移植有不同的影响,我使用过以下三种 ...

  4. Springcloud 整合Hystrix 断路器,支持Feign客户端调用

    1,在这篇博文中,已经大致说过了Springcloud服务保护框架 Hystrix在服务隔离,服务降级,以及服务熔断中的使用 https://www.cnblogs.com/pickKnow/p/11 ...

  5. [RH134] 10-NFS和Samba客户端

    NFS和samba服务器的配置,请参考: 这里,我们只讨论客户端的使用 1.NFS客户端的使用 nfs实现的是类Unix系统之间的远程共享目录. 假设我们已经有一个提供nfs服务的服务器,IP为192 ...

  6. IntelliJ Idea 中文乱码问题

    首先,Idea真的是一款很方便的开发工具,但是关于中文乱码这个问题我不得不吐槽,这个编码也弄得这么麻烦干嘛呀...下面就说一下怎么解决中文乱码问题: 1.首先是编辑器的乱码,这个很好解决,file-& ...

  7. Codeforces题解集 1.0

    记录 Codeforces 2019年12月19日到 2020年2月12日 的部分比赛题 Educational Codeforces Round 82 (Rated for Div. 2) D Fi ...

  8. 金三银四科学找工作,用python大数据分析一线城市1000多份岗位招聘需求

    文章每周持续更新,各位的「三连」是对我最大的肯定.可以微信搜索公众号「 后端技术学堂 」第一时间阅读(一般比博客早更新一到两篇) 每年的三四月份是招聘高峰,也常被大家称为金三银四黄金招聘期,这时候上一 ...

  9. PTA数据结构与算法题目集(中文) 7-19

    PTA数据结构与算法题目集(中文)  7-19 7-19 求链式线性表的倒数第K项 (20 分)   给定一系列正整数,请设计一个尽可能高效的算法,查找倒数第K个位置上的数字. 输入格式: 输入首先给 ...

  10. 安装部署Tomcat服务器

                      安装部署Tomcat服务器 案例1:安装部署Tomcat服务器 案例2:使用Tomcat部署虚拟主机 案例3:使用Varnish加速Web 1案例1:安装部署Tom ...