LightOJ 1138 Trailing Zeroes (III) 打表
就是统计5,然后当时因为发现最多有8000w个5的倍数,然后8000w/100,是80w,打表,二分找
然后我看网上的都是直接二分找,真是厉害
#include <cstdio>
#include <iostream>
#include <ctime>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N=1e8;
const int INF=0x3f3f3f3f;
int cnt[],a[];
int main()
{
int ans=,pos=;
for(int i=,j=;;i+=,++j){
int t=i;
while(t%==)++ans,t/=;
if(ans>=N){
break;
}
if(j%==){
cnt[++pos]=ans;
a[pos]=i;
}
}
cnt[++pos]=N+;
a[pos]=*N+;
int cas=,T;
scanf("%d",&T);
while(T--){
int n,res=-;
scanf("%d",&n);
int k=lower_bound(cnt+,cnt++pos,n)-cnt;
if(cnt[k]==n)res=a[k];
else {
--k;
int l=,sum=;
if(k!=)l=a[k]+,sum=cnt[k];
for(;l<a[k+];l+=){
int t=l;
while(t%==)t/=,++sum;
if(sum>=n){
break;
}
}
if(sum==n)res=l;
}
printf("Case %d: ",++cas);
if(res==-)printf("impossible\n");
else printf("%d\n",res);
}
return ;
}
LightOJ 1138 Trailing Zeroes (III) 打表的更多相关文章
- LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)
http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS M ...
- LightOj 1138 - Trailing Zeroes (III) 阶乘末尾0的个数 & 二分
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题意:给你一个数n,然后找个一个最小的数x,使得x!的末尾有n个0:如果没有输出 ...
- lightoj 1138 - Trailing Zeroes (III)【二分】
题目链接:http://lightoj.com/volume_showproblem.php? problem=1138 题意:问 N. 末尾 0 的个数为 Q 个的数是什么? 解法:二分枚举N,由于 ...
- LightOj 1138 Trailing Zeroes (III)
题目描述: 假设有一个数n,它的阶乘末尾有Q个零,现在给出Q,问n最小为多少? 解题思路: 由于数字末尾的零等于min(因子2的个数,因子5的个数),又因为2<5,那么假设有一无限大的数n,n= ...
- 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 ...
- 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 ...
- 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. 我们可以知 ...
随机推荐
- 第二章 Qt常用工具的介绍
第二章 Qt常用工具的介绍 (1)No.1 qmake 相信编写过Makefile的开发人员,随着工程中源码的级数递增和以类型.功能.模块组织源码的子目录的增多,都不愿意重复机械地手工编写这个工程管理 ...
- ASP.NET MVC Web API使用示例
上篇博客讲解rest服务开发时,曾经提到过asp.net mvc中的rest api,由于篇幅原因,没有在上篇博客中进行讲解,这里专门拿出来进行讨论.还是一样引用上次的案例,用asp.net mvc提 ...
- Mac 平台下安装 OpenVC
opencv for Mac I 背景 Mac(Ios 9.0), 时间: 2015年11月. 本人也是小白,在网上爬了几天才安装好. II 安装OpenCV for Mac 首先下载op ...
- Cassandra1.2文档学习(4)——分区器
参考文档:http://www.datastax.com/documentation/cassandra/1.2/webhelp/index.html#cassandra/architecture/a ...
- CRF图像语义分割
看了Ladicky的文章Associative Hierarchical CRFs for Object Class Image Segmentation,下载他主页的代码,文章是清楚了,但代码的RE ...
- Django视图函数
一.视图函数 1. 视图函数的第一个参数一定是一个HTTPRequest类型的对象,这个对象是Django自动创建的,具体形参名通常用request.通过这个对象,可以调用请求的一些参数,比如requ ...
- Java学习--Equals与“==”
在Java规范中,它对equals()方法的使用必须要遵循如下几个规则: equals 方法在非空对象引用上实现相等关系: 1.自反性:对于任何非空引用值 x,x.equals(x) 都应返回 tru ...
- 一步步学习NHibernate(1)——NHibernate介绍
请注明转载地址:http://www.cnblogs.com/arhat 第十五章 从本章开始,老魏将给大家一起学习NHibernate这个流行的ORM框架,本来老魏想要和大家一起探讨微软的EF框架的 ...
- vm安装ubuntu桥接模式无法联网
桥接模式,就是和主机不同的ip,其他都是一样的. 编辑网络连接 查看自己机子的ip ipconfig 一般情况下是 ip 192.168.1.XXX 子网掩码 255.255.255.0 网关 192 ...
- ubuntu下安装ssh
vm安装ubunt后,无法连接ssh,一般情况是防火墙的问题,或者SSH没有安装. 防火墙 1.查看防火墙 sudo ufw status 2,关闭防火墙 sudo ufw disable ssh 1 ...