1138 - Trailing Zeroes (III)
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

题解:这道题要找末尾0的个数所需要的最小阶乘,因为想到10=2*5,然而2是很多数的质因数,数目要大于质因数5的数目,所以只考虑5的质因数的个数,便为末尾0的个数,所以

int q=0;
while(x){
q+=x/5;
x/=5;
}

这点便可以得出x!末尾0的个数;

用二分,从无穷大开始找,找到Q就是答案;

代码:

 #include<stdio.h>
const int MAXN=0x3f3f3f3f;//这个要足够大才能找到10^8
int getq(int x){
int q=;
while(x){
q+=x/;
x/=;
}
return q;
}
void erfen(int n){
int l=,r=MAXN;
while(l<=r){
int mid=(l+r)>>;
if(getq(mid)>=n)r=mid-;//二分这点注意
else l=mid+;
}
if(getq(l)==n)printf("%d\n",l);
else puts("impossible");
}
int main(){
int T,Q,flot=;
scanf("%d",&T);
while(T--){
scanf("%d",&Q);
printf("Case %d: ",++flot);
erfen(Q);
}
return ;
}

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

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

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

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

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

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

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

  5. lightoj 1138 - Trailing Zeroes (III)【二分】

    题目链接:http://lightoj.com/volume_showproblem.php? problem=1138 题意:问 N. 末尾 0 的个数为 Q 个的数是什么? 解法:二分枚举N,由于 ...

  6. Trailing Zeroes (III) LightOJ - 1138 二分+找规律

    Time Limit: 2 second(s) Memory Limit: 32 MB You task is to find minimal natural number N, so that N! ...

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

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

  8. Trailing Zeroes (III) (二分)题解

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

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

随机推荐

  1. debian install & configure(2)-drivers-nvidia

    ==========================================手动编译卸载受限驱动 :apt-get --purge remove nvidia-*apt-get --purge ...

  2. Oracle EBS-SQL (PO-9):检查期间采购订单执行情况.sql

    --采购订单执行情况查询(七天内接收情况)select pha.segment1       采购订单,         msib.segment1      物料编码,         pla.qu ...

  3. 0-20ma 0-5V,0-10V ,0-15V ,0-20V,0-30V模拟量(范围可以定制)多功能采集模块,支持1路继电器输出,2路Di输入,8路Ai输入,可电脑控制,支持485 modbus rtu协议。端口参数可以配置保存,支持定制修改。

    多功能模拟量采集模块MRD-5017具有8 通道模拟量采集(支持0-20mA,0-5V,0-10V混合测量),2路DI,1路继电器输出,1路485接口(支持MODBUS RTU),能实现8路AI(12 ...

  4. BadgeView新提示开源工具类

    BadgeView是使用某个图标作为新功能的提醒,类似于收到短息后短信图标的右上方有信息数目或者其他的显示性提示.BadgeView很好的实现了这个功能,而且进行了拓展,可自定义位置和提示图标. 工具 ...

  5. 网易云课堂_程序设计入门-C语言_第三周:循环_1奇偶个数

    1 奇偶个数(5分) 题目内容: 你的程序要读入一系列正整数数据,输入-1表示输入结束,-1本身不是输入的数据.程序输出读到的数据中的奇数和偶数的个数. 输入格式: 一系列正整数,整数的范围是(0,1 ...

  6. 采用OSChina代码托管管理项目(一)

    .Git是什么 Git在Wikipedia上的定义:它是一个免费的.分布式的版本号控制工具,或是一个强调了速度快的源码管理工具. Git最初被Linus Torvalds开发出来用于管理Linux内核 ...

  7. 常用的sql server规范

    常见的字段类型选择1.字符类型建议采用varchar/nvarchar数据类型2.金额货币建议采用money数据类型3.科学计数建议采用numeric数据类型4. 自增长标识建议采用bigint数据类 ...

  8. 关于vs启动调试报错:CS0016: 未能写入输出文件“xxxxxxxx”--“目录名称无效。”解决方法

    很多人都会遇到这个错误,网友说一般这错误都是由于权限引起,我尝试按照博客写的方法,解决失败!http://www.cnblogs.com/finesite/archive/2011/01/28/194 ...

  9. UIPasteboard 粘贴板

    UIPasteboard *pasteboard = pasteboard.string = self.label.text;

  10. EJB QI查询

    EO.PNAME like ?1 OR  EO.PNAME like ?2";      Query query = entityManager.createNativeQuery(quer ...