vjudge Trailing Zeroes (III) (二分答案 && 数论)
嗯...
题目链接:https://vjudge.net/contest/318956#problem/E
这道题是二分答案+数论,但首先是数论,否则你不知如何二分...
首先关于一个阶乘的结果最后会出现0(即10),肯定是由2 * 5所造成的,而对于正整数 N,在[0, N]范围内,质因子中含有 2 的总是会比质因子含有 5 的要多。所以,只要需要知道质因数含有 5 的数字有多少个,即可知道末尾连续出现 0 的个数有多少...
然后我们进行二分答案,从1~5e8 + 5(一定要足够大!)进行二分,如果当前答案处理出来的5的个数正好等于a,那么它可能是答案,因为可能我们把较小的遗漏了,所以我们要继续二分,如果有比它小的,继续更新...
AC代码:
#include<cstdio>
#include<iostream> using namespace std; inline int check(int x){
int ans = ;
while(x){
ans += x / ;
x /= ;
}
return ans;
}//处理5的个数,即末尾0的个数 int main(){
int t, m = ;
scanf("%d", &t);
while(t--){
int ans = , a;
m++;
scanf("%d", &a);
int l = , r = 5e8 + ;
while(l <= r){
int mid = (l + r) >> ;
int _mid = check(mid);
if(_mid > a) r = mid - ;
else if(_mid < a) l = mid + ;
else if(_mid == a) {ans = mid; r = mid - ;}//可能有答案遗漏
}
if(ans) printf("Case %d: %d\n", m, ans);
else printf("Case %d: impossible\n", m);
}
return ;
}
AC代码
vjudge 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 ...
- Trailing Zeroes (III) 假设n!后面有x个0.现在要求的是,给定x,要求最小的n; 判断一个n!后面有多少个0,通过n/5+n/25+n/125+...
/** 题目:Trailing Zeroes (III) 链接:https://vjudge.net/contest/154246#problem/N 题意:假设n!后面有x个0.现在要求的是,给定x ...
随机推荐
- Python求1000以内所有3或5的倍数的和。
a=0 for n in range(1,1000): if n%3==0 or n%5==0: a=a+n print(a) 运行结果: 233168
- MongoDB C#驱动使用方法
string connStr = ConfigurationManager.ConnectionStrings["MongoDBConnStr"].ConnectionString ...
- 创建Vue项目及其内容分析
利用 vue 脚手架开发企业级应用 # 全局安装 vue-cli npm install --global vue-cli # 创建一个基于 webpack 模板的新项目 ...
- Go_io操作
I/O操作也叫输入输出操作.其中I是指Input,O是指Output,用于读或者写数据的,有些语言中也叫流操作,是指数据通信的通道. Golang 标准库对 IO 的抽象非常精巧,各个组件可以随意组合 ...
- iptables详解(2):四表五链
关于iptables中“四表五链”,我们今天来好好唠唠: 1.表的概念: 我们把具有相同功能的规则的集合叫做"表",所以说,不同功能的规则,我们可以放置在不同的表中进行管理,而ip ...
- 【Python】爬虫原理
前言 简单来说互联网是由一个个站点和网络设备组成的大网,我们通过浏览器访问站点,站点把HTML.JS.CSS代码返回给浏览器,这些代码经过浏览器解析.渲染,将丰富多彩的网页呈现我们眼前: 一.爬虫是什 ...
- Vue集成openlayers
1.安装ol库 使用cnpm i ol -s命令安装 2.建一个olMap.vue文件夹 <template> <div class='olMap'> <h2>{{ ...
- Centos6.10-FastDFS-Tracker-Nginx示例配置
nginx 安装过程<详见> 1.进入工作目录 cd /usr/local/nginx/conf 2.创建子目录 mkdir configs 3.创建storage代理配置 cd conf ...
- 一篇文章带你了解JavaScript中的变量,作用域和内存问题
1 在JavaScript中的变量分别区分为两种: 一种为基本类型值,一种为应用类型值. 基本类型值指的是简单的数据段 引用类型值为可能由多个值组成的对象 引用类型的值是保存在内存中的对象,JavaS ...
- aria2连接网站出现handshake failure问题的分析与解决方法
aria2是一款轻量级的,支持多协议,跨平台的命令行下载工具,是笔者目前在使用的下载工具,结合uget使用基本上能媲美window下的迅雷工具.在笔者使用过程中,遇到了aria2连接部分网站时出现ha ...