C - Trailing Zeroes (III)(二分)
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
AC代码
- #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 ;
- }
C - Trailing Zeroes (III)(二分)的更多相关文章
- 1138 - Trailing Zeroes (III) 二分
1138 - Trailing Zeroes (III) You task is to find minimal natural number N, so that N! contains exa ...
- Light oj 1138 - Trailing Zeroes (III) (二分)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N. 我们可以知 ...
- 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 ...
- Trailing Zeroes (III)(lightoj 二分好题)
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)
http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS M ...
- 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 ...
- light oj 1138 - Trailing Zeroes (III)【规律&&二分】
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- Light oj 1138 - Trailing Zeroes (III) 【二分查找 && N!中末尾连续0的个数】
1138 - Trailing Zeroes (III) problem=1138"> problem=1138&language=english&type=pdf&q ...
- LightOJ Trailing Zeroes (III) 1138【二分搜索+阶乘分解】
1138 - Trailing Zeroes (III) PDF (English) problem=1138" style="color:rgb(79,107,114)" ...
- Trailing Zeroes (III) -;lightoj 1138
Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Y ...
随机推荐
- Office文件的奥秘——.NET平台下不借助Office实现Word、Powerpoint等文件的解析
Office文件的奥秘——.NET平台下不借助Office实现Word.Powerpoint等文件的解析 分类: 技术 2013-07-26 15:38 852人阅读 评论(0) 收藏 举报 Offi ...
- 常见ETL工具一览,你知多少?
这些年,几乎都与ETL打交道,接触过多种ETL工具.现将这些工具做个整理,与大家分享. 一 ETL工具[国外] 1. datastage点评:最专业的ETL工具,价格不菲,使用难度一般 下载地址:ft ...
- yield生成器的经典案例
如何生成斐波那契數列 斐波那契(Fibonacci)數列是一个非常简单的递归数列,除第一个和第二个数外,任意一个数都可由前两个数相加得到.用计算机程序输出斐波那契數列的前 N 个数是一个非常简单的问题 ...
- SpringMVC注解示例
1.web.xml <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-cla ...
- Hibernate错误及解决办法
1.Hibernate 报错:this project is not a myeclipse hibernate project . assuming hibernate 3 cap res:项目名上 ...
- Building Performant Expand & Collapse Animations
t's starting to be pretty common knowledge that there are only 2 things you can animate cheaply in C ...
- JavaUtil_08_StringUtil_commons-lang3 之 StringUtils
二.参考资料 1.[commons]字符串工具类——commons-lang3之StringUtils
- I.MX6 USB Camera
/************************************************************************* * I.MX6 USB Camera * 说明: ...
- 小米5安装Xposed框架——需要解锁刷机
Xposed官网 https://forum.xda-developers.com/xposed 官方模块厂库 https://repo.xposed.info/ 中文站点 https://xpose ...
- SPOJ375Query on a tree I(树剖+线段树)(询问边)
ιYou are given a tree (an acyclic undirected connected graph) with N nodes, and edges numbered 1, 2, ...