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. 我们可以知 ...
随机推荐
- Oracle外部表详解(转载)
(外部表创建主要注意创建目录访问权限问题.目录路径格式无空格等不相关字符,即必须是当前表访问用户可以访问:关于表中行数的限制问题,如果不加限制注意添加reject limit unlimited:表中 ...
- ASP.NET DataList嵌套实现评论效果
问题: Datalist1显示say这个表的数据 然后想在Datalist1中嵌套一个Datalist2用于显示对应的评论表2的 sayID对应表1的id,若表2中找不到对应sayId则在对应的Dat ...
- ASP.NET MVC3实现无刷新验证码
在MVC中进行留言,评论等功能时,不可避免会用到表单提交时的验证码问题,有时,我们的作法是,当表单被提交后,在controller里去判断验证码的正确与否,但我认为这种用户体验是很差的,今天正好有后时 ...
- Android Studio API 文档_下载与使用
如何下载API 说明: 时间: 2016/7/9 根据百度经验步骤改编(百度经验), 但是比它更好, 亲测可用 1.1 下载API文档: 1.1.1 SDK Manager 1.1.2 1.1.3 ( ...
- PHP学习心得(二)——实用脚本
<?php 来表示 PHP 标识符的起始,然后放入 PHP 语句并通过加上一个终止标识符 ?> 来退出 PHP 模式 调用函数phpinfo(),将会看到很多自己系统的信息,以及预定义变量 ...
- 大数据时代的技术hive:hive的数据类型和数据模型
在上篇文章里,我列举了一个简单的hive操作实例,创建了一张表test,并且向这张表加载了数据,这些操作和关系数据库操作类似,我们常把hive和关系数据库进行比较,也正是因为hive很多知识点和关系数 ...
- Python原型模式
如果想根据现有对象复制出新的对象并对其修改,可以考虑原型模式(Prototype Pattern) class Point: __slots__ = ("x", "y&q ...
- android开发两种退出程序方式(killProcess,System.exit)
KillProcess: 在android中我们如果想要程序的进程结束可以这样写: android.os.Process.killProcess(android.os.Process.myPid()) ...
- 洛谷1508 Likecloud-吃、吃、吃
题目背景 问世间,青春期为何物? 答曰:“甲亢,甲亢,再甲亢:挨饿,挨饿,再挨饿!” 题目描述 正处在某一特定时期之中的李大水牛由于消化系统比较发达,最近一直处在饥饿的状态中.某日上课,正当他饿得头昏 ...
- 新增tab页无法获取到数据,原来是URL的rewrite配置文件忘了修改
昨天怎么也不明白为什么就是不能短网址访问,而且更迷惑的是居然数据也获取不到. 今天早上在网上搜ThinkPHP,想学习下这个框架.虽然知道是MVC模式,但是URL数据传递到底有什么阀门是我尚未了解到的 ...