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. hdu1541树状数组(降维打击)

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1541/ 题意是:在二维图上有一系列坐标,其中坐标给出的顺序是:按照y升序排序,如果y值相同则按照x升序排序.这个 ...

  2. 实例演示:如何简化生产中的Pod安全策略?

    Pod安全策略对于强化K8S集群安全至关重要.本文将延续之前的文章继续深入介绍Pod安全策略. 首先,简单介绍了如何将Pod与Pod安全策略相关联,并使用RBAC来展示具体步骤.然后介绍如何在Ranc ...

  3. 《深入理解 Java 虚拟机》读书笔记:Java 内存模型与线程

    正文 由于计算机的处理器运算速度与它的存储和通信子系统速度的差距太大了,大量的时间都花费在磁盘 I/O.网络通信或者数据库访问上,导致处理器在大部分时间里都处于等待其他资源的状态.因此,为了充分利用计 ...

  4. 使用FME平移shapefile文件

  5. office2010安装与破解,笔者亲测可用!!!!!!

    我们首先需要准备office2010安装包与破相应的破解软件.软件包的获取方式:扫码关注[猿成长],,回复 office2010安装,即可获取,下载解压后文件目录结构如下图所示: 打开安装程序文件夹, ...

  6. 浅谈SQL Server、MySQL中char,varchar,nchar,nvarchar区别

    最近一次的面试中,被面试官问到varchar和nvarchar的区别,脑海里记得是定长和可变长度的区别,但却没能说出来.后来,在网上找了下网友总结的区别.在这里做个备忘录: 一,SQL Server中 ...

  7. vue配置环境踩坑

    Vue 环境配置踩坑 目录 Vue 环境配置踩坑 windows下cnpm -v :无法将"cnpm"项识别为 cmdlet.函数.脚本文件或可运行程序的名称. windows下c ...

  8. 关于dll劫持我的奇思妙想(一)

    0x00  前言 前段时间在研究着windows底层的一些东西,发现这个dll劫持一直没有做过,根据倾旋师傅的视频和文章做了一系列的研究,然后就突发来了兴致研究一些dll劫持提权. 0x01   了解 ...

  9. Spring-Cloud-Netflix-系统架构

    目录 系统架构 概述 集中式架构 概述 特点 垂直拆分 概述 特点 系统架构分类 微服务 微服务的特点: 分布式服务: 微服务和分布式的区别: 微服务要面临的问题: springClould是什么 远 ...

  10. C 怪兽游戏

    时间限制 : - MS   空间限制 : - KB  评测说明 : 1s,256m 问题描述 何老板在玩一款怪兽游戏.游戏虽然简单,何老板仍旧乐此不疲.游戏一开始有N只怪兽,编号1到N.其中第i只怪兽 ...