Time Limit: 2 second(s) Memory Limit: 32 MB

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

Output for Sample Input

3

1

2

5

Case 1: 5

Case 2: 10

Case 3: impossible

题意:求出现一个最小的数的阶乘满足末尾有连续q个0。

思路:一个最小的数末尾要出现0一定要是能被5或10整除的,0的连续长度与数组大小正相关,故二分数字得解。

 #include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<limits.h>
#include<algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF=1e9;
typedef unsigned long long ll;
typedef long long LL;
int main()
{
int T,cases=;
scanf("%d",&T);
while(T--)
{
int q;
LL ans=-;
scanf("%d",&q);
int l=,r=q*,mid;//为什么右端点是q*5,因为q*5>=ans.想一想为什么(hint:刚才那个序列。。。)
while(l<=r)
{
mid=(l+r)/;
int m=mid,wu=,count=;
while(m>=wu)
{
int p=m;
p/=wu;
count+=p;
wu*=;
}
if(count==q)
{
ans=mid;
break;
}
else if(count>q)
r=mid-;
else
l=mid+;
}
if(ans==-)
printf("Case %d: impossible\n",cases++);
else
printf("Case %d: %lld\n",cases++,ans/*);
}
}

代码转自(https://blog.csdn.net/duan_1998/article/details/72566106)

Trailing Zeroes (III) LightOJ - 1138 二分+找规律的更多相关文章

  1. Trailing Zeroes (III) LightOJ - 1138 不找规律-理智推断-二分

    其实有几个尾零代表10的几次方但是10=2*510^n=2^n*5^n2增长的远比5快,所以只用考虑N!中有几个5就行了 代码看别人的: https://blog.csdn.net/qq_422797 ...

  2. Trailing Zeroes (III) LightOJ - 1138(二分)

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

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

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

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

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

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

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

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

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

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

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

  8. 1138 - Trailing Zeroes (III) 二分

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

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

随机推荐

  1. 精讲 使用ELK堆栈部署Kafka

    使用ELK堆栈部署Kafka 通过优锐课的java架构学习分享,在本文中,我将展示如何使用ELK Stack和Kafka部署建立弹性数据管道所需的所有组件. 在发生生产事件后,恰恰在你最需要它们时,日 ...

  2. 可能对Flutter应用程序开发有用的代码/库/专有技术列表

    当我开始使用Flutter实施该应用程序时,我开始担心“如何最好地编写?”以及“如何使其更好地放置?”. 在这种情况下,您将需要参考GitHub上发布的代码和应用程​​序. 因此,我收集了似乎对Flu ...

  3. English Grammar - Subject Clause

    that引导主语从句 一般置于句末,偶尔也置于句首 that引导的主语从句置于句首 That the seas are being overfished has been known for year ...

  4. centos 下使用 pytesseract 识别文字

    偶发一个想法搭一个验证码识别工具,网上查了一下有Tesseract 这个工具可以识别,所以有了后面一小时的搭建过程 ps:Ubuntu 下似乎可以直接用包管理工具来安装,我使用的源码编译安装 前提 由 ...

  5. drf偏移分页组件-游标分页-自定义过滤器-过滤器插件django-filter

    drf偏移分页组件 LimitOffsetPagination 源码分析:获取参数 pahenations.py from rest_framework.pagination import Limit ...

  6. UI Automation技术获取cmd或Powershell命令提示符窗口的实时内容

    事先打开的Powershell或cmd窗口中的文本,用其他方式难以拿到.但是用UI Automation可以轻松获取.本工具在窗体上加入了一个Timer控件,每秒钟都查找桌面上是否有Powershel ...

  7. Django框架的安装与使用

    Django框架的安装与使用 在使用Django框架开发web应用程序时,开发阶段同样依赖wsgiref模块来实现Server的功能,我们使用Django框架是为了快速地开发application, ...

  8. 第04项目:淘淘商城(SpringMVC+Spring+Mybatis)【第十天】(单点登录系统实现)

    https://pan.baidu.com/s/1bptYGAb#list/path=%2F&parentPath=%2Fsharelink389619878-229862621083040 ...

  9. Linux介绍,基本命令

  10. CCP 协议

    转载 1.  CCP协议概述 CCP(CAN Calibration Protocol)是一种基于CAN总线的匹配标定协议.ECU都需要经过匹配标定的过程,从而确定其运行参数和控制参数.有时为了实现对 ...