嗯...

题目链接: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) (二分答案 && 数论)的更多相关文章

  1. 1138 - Trailing Zeroes (III) 二分

    1138 - Trailing Zeroes (III)   You task is to find minimal natural number N, so that N! contains exa ...

  2. Light oj 1138 - Trailing Zeroes (III) (二分)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N. 我们可以知 ...

  3. 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 ...

  4. Trailing Zeroes (III)(lightoj 二分好题)

    1138 - Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit:  ...

  5. LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)

    http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS     M ...

  6. 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 ...

  7. light oj 1138 - Trailing Zeroes (III)【规律&&二分】

    1138 - Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit:  ...

  8. Light oj 1138 - Trailing Zeroes (III) 【二分查找 &amp;&amp; N!中末尾连续0的个数】

    1138 - Trailing Zeroes (III) problem=1138"> problem=1138&language=english&type=pdf&q ...

  9. 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 ...

随机推荐

  1. lminus

    lminus是Synopsy自带的tcl list 操作command. 顾名思义,可以将两个list相减,即过滤掉两个list中相同的element,生成一个新的list,其实是用lsearch与l ...

  2. jmeter+influxdb+granfana+collectd监控cpu+mem+TPS

    1.安装grafana #####gafana过期安装包安装报错 Error unpacking rpm package grafana-5.1.4-1.x86_64error: unpacking ...

  3. NW.js构建桌面应用

    最近要做个桌面的应用,用起来也方便.找了一圈发现NW.js挺容易上手,分享给大家. NW.js 官网https://nwjs.io/ 1.下载适合当前版本的js [这里下载的SDK版本,方便后续调试] ...

  4. 线性筛-euler,强大O(n)

    欧拉函数是少于或等于n的数中与n互质的数的数目 φ(1)=1(定义) 类似与莫比乌斯函数,基于欧拉函数的积性 φ(xy)=φ(x)φ(y) 由唯一分解定理展开显然,得证 精髓在于对于积性的应用: ){ ...

  5. nginx的负载均衡配置

    1.下载nginx的压缩包,可以去官网下载 2.解压缩,可以看到其中有个conf的文件夹,在该目录中,nginx.conf配置文件就是核心配置文件 3.默认配置 #user nobody; worke ...

  6. MySQL命令行脚本

    1. 命令行连接 打开终端,运行命令 mysql -uroot -p 回车后输入密码,当前设置的密码为mysql 退出登录 quit 和 exit 或 ctrl+d 查看版本:select versi ...

  7. 【Python】 运算符

    什么是运算符? 本章节主要说明Python的运算符.举个简单的例子 4 +5 = 9 . 例子中,4 和 5 被称为操作数,"+" 称为运算符. 接下来让我们一个个来学习Pytho ...

  8. 20-02-27 hive表的几个问题

    1.hive表的动态分区 2.hive  表如何修改列名 3.group  by  对统计指标的影响  (group by 的本质) 4.row_number 对数据的影响

  9. c# Linq List<T>去除其中重复的项

    //要去重的 list<T> listTest: var resultlist= listTest.GroupBy(p =>p.Id).Select(g => g.First( ...

  10. Python jupuyter 的安装与使用(windows下)

    1.win+R  cmd 打开命令窗 2.pip install jupyter pip安装jupyter 3.安装好后 执行jupyter的启动命令: jupyter notebook --ip=0 ...