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
思路:
有几个零就是看能分解出几个5,所以用二分查找是否存在能分解出n个5的数
代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<iostream>
#include<algorithm>
#define INF 0x3f3f3f3f
#define ll long long
const int N=1e5+5;
const int MOD=1000;
const double C=0.57721566490153286060651209;
using namespace std;
ll judge(int x){ //判断数x能分解出5的个数
ll res=0;
while(x){
res+=x/5;
x/=5;
}
return res;
}
ll panduan(ll n){
ll l=0,r=5e8+1;
ll mid,res;
while(r>=l){
mid=(l+r)/2;
if(judge(mid)>=n){
res=mid;
r=mid-1;
}
else{
l=mid+1;
}
}
return res;
}
int main(){
int T,num=1;
ll ans,n;
ll mid,l,r;
scanf("%d",&T);
while(T--){
scanf("%lld",&n);
int ans=panduan(n);
if(judge(ans)==n){
printf("Case %d: %lld\n",num++,ans);
}
else{
printf("Case %d: impossible\n",num++);
}
}
return 0;
}
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: ...
- light oj 1138 - Trailing Zeroes (III)【规律&&二分】
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) 【二分查找 && 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 ...
随机推荐
- [python-opencv] 模糊操作
@不要在奋斗的年纪 选择安逸 均值模糊 中值模糊 自定义模糊 意义与应用场景 模糊的基本原理: 1.基于离散卷积 2.定义好每个卷积核 3.不同卷积核得到不同的卷积效果 4.模糊是卷积的一种表象 #均 ...
- java Arrays.asList 问题
1.问题 public static void asList() { System.out.println(Arrays.asList(new String[] { "a", &q ...
- eclipse整合spring+springMVC+Mybatis
一.新建Maven项目 点击菜单栏File项,选择New->Project,选中Maven Project,如下图: 二.配置pom.xml <?xml version="1.0 ...
- 使用Lotus Enterprise Integrator (LEI)将Domino附件移至关系数据库(图文过程)
参考IBM解决方案:http://www.ibm.com/developerworks/cn/lotus/LEI-attachments/index.html 转载请注明出处:http://blog. ...
- Linux中Kill掉进程的10种方法
常规篇: 首先,用ps查看进程,方法如下: 复制代码 代码如下: $ ps -ef……smx 1822 1 0 11:38 ? 00:00:49 gnome-terminalsmx 1823 1822 ...
- C++(STL)&&树-堆结构练习——合并果子之哈夫曼树
题目题解:http://blog.csdn.net/xu12110501127/article/details/9199335 有关博客:http://www.360doc.com/content/1 ...
- php中&运算符的理解与使用
php的引用(就是在变量或者函数.对象等前面加上&符号) 在PHP 中引用的意思是:不同的名字访问同一个变量内容. 变量的引用 PHP 的引用允许你用两个变量来指向同一个内容 例一: < ...
- 在ASP.NET Web Application中通过SOAP协议调用Bing搜索服务
本文介绍了如何在ASP.NET Web Application中将Bing搜索作为Web Service来使用,并通过HTTP的SOAP协议在ASP.NET Web Application中调用Bin ...
- 机器学习理论基础学习9--- EM 算法
EM算法的适用场景: EM算法用于估计含有隐变量的概率模型参数的极大似然估计,或者极大后验概率估计. 当概率模型既含有观测值,又含有隐变量或潜在变量时,就可以使用EM算法来求解概率模型的参数. 当概率 ...
- MVC5+Easyui1.3.6+EF6 开发部分备忘笔记
一点一点增加,后面继续. 1.Row Editing in DataGrid 编辑,总是绑定不了checkbox的问题