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. 我们可以知 ...
随机推荐
- highcharts图表
最近项目中用到highcharts雷达图,如下 其实echarts就不错,echarts用canvas,highcharts用svg,各有特点 代码如下: index.html <!doctyp ...
- 客户端(android,ios)与服务器通信
android,ios客户端与服务器通信为了便于理解,直接用PHP作为服务器端语言 其实就是一个 http请求响应的过程序,先从 B/S模式说起浏览器发起http请求,服务器响应请求,并把数据返回给浏 ...
- java oop
/** 多层嵌套内部类, 调用时要层层往下调用 格式: 外部类.内部类1.内部类2 对象名 = new 外部类().new 内部类1().new 内部类2(); 对象名.属性/方法名(); */ cl ...
- jQuery EasyUI之DataGrid使用示例
jQuery EasyUI是一个轻量级的Web前端开发框架,提供了很多的现成组件帮助程序员减轻前端代码开发量,之前有个项目中就用到了其中的DataGrid. jQuery EasyUI框架的官方主页: ...
- java StringBuffer与StringBuilder
StringBuffer:就是字符串缓冲区. * 用于存储数据的容器. * 特点: * 1,长度的可变的. * 2,可以存储不同类型数 ...
- TDD三大定律
You must write a failing unit test before you write production code. You must stop writing that unit ...
- 转:testlink 环境搭建(傻瓜版)
testlink 环境搭建(傻瓜版) 2011-11-24 22:23 by 虫师, 12322 阅读, 4 评论, 收藏, 编辑 今天抽了点时间把testlink 环境搭建了一下,一直觉得这东西不怎 ...
- MaskedTextBox控件实现输入验证
Mask属性可以验证用户在文本中输入数据的格式 this.maskedTextBox1.Mask = "000000-00000000-000A";//身份证号码18位 this. ...
- 闲谈前端编码解码、C#编码解码。
最近做项目,出现中文乱码的问题,特地研究一下. GB2312,指的是中文 UTF8,指的是国标,包含中文.英文. 但是通过JQuery.ajax的Get.Post,如果直接传递中文或者特殊字符的特使字 ...
- StringBuffer与StringBuilder原理与区别
其实只要找下Google大神就有答案了:StringBuffer 与 StringBuilder 中的方法和功能完全是等价的,只是StringBuffer 中的方法大都采用了 synchronized ...