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 ...
随机推荐
- 洛谷P4168 蒲公英 [Violet] 分块
题解:分块+离散化 解题报告: 一个分块典型题呢qwq还是挺妙的毕竟是道黑题 然,然后发现忘记放链接了先放链接QAQ 有两三种解法,都港下qwq 第一个是O(n5/3)的复杂度,谢总说不够优秀没有港, ...
- mysql 用户与权限
1.用户 1)创建用户 "create user '用户'@'host' identified by '密码';" 在5.7以后的版本中要求密码包含至少一个大写字母,一个小写字 ...
- 如何设置dedecms自定义表单必填项?
用dedecms自定义表单可以制作一个简单的预约系统,有些相关信息需要设置为必填项,比如联系方式,没有留下真实的电话或其他信息,以后要怎么联系到你的客户.那我们要如何设置织梦cms自定义表单必填项呢? ...
- android返回到第一个activity
问题:Android顺序打开多个Activity,如何返回到第一个Activity(一般为首页)? 情形:如 A 打开 B, B 打开 C, C 打开 D, 然后如果从 D 一步返回到 A,并清楚掉 ...
- 7 jmeter之参数化
badboy里参数化(前面4 jmeter badboy脚本开发技术详解已讲过) jmeter里参数化-1 用户参数 1.打开badboy工具,点击红色按钮开始录制,在地址栏目中输入地址:www.so ...
- word自动导入目录
1:如果在编写word时,有给各章添加标题,可以使用word的目录生成功能,如图:
- Kylin构建cube时状态一直处于pending
在安装好kylin之后我直接去访问web监控页面发现能够进去,也没有去看日志.然后在运行官方带的例子去bulid cube时去发现状态一直是pending而不是runing.这个时候才去查看日志: 2 ...
- 配置apache实现对网站某一目录的访问自动跳转到指定目录
访问www.baidu.com/Hello目录,实际访问/new_balance/hello2 Alias /Hello/ /new_balance/hello2 <Directory /new ...
- PHP 自定义header 参数获取的问题
有的情况下,我们需要把参数放在Headers 里传递.比如说与提供给移动端的api,不能进行缓存的时候. 但是,自定义的header 经常是拿不到的. 如果是apache 的服务器,可以用 apach ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON SetComprise2
zw版[转发·台湾nvp系列Delphi例程]HALCON SetComprise2 procedure TForm1.Button1Click(Sender: TObject);var op : H ...