嗯...

题目链接: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. 初识hadoop --- (分布式文件系统 + 分块计算)

    [转载] + 整理 2016-11-18 使用范围: Hadoop典型应用有:搜索.日志处理.推荐系统.数据分析.视频图像分析.数据保存等. Hadoop历史 雏形开始于2002年的Apache的Nu ...

  2. splay(1区间翻转区间最值与区间修改)

    bzoj1251权限题 题目点这里,你懂得 直接上板子,这个要好好体会 操作是最经典的. #include <algorithm> #include <iostream> #i ...

  3. eclipse提示错误:save could not be completed

    原博客地址:https://blog.csdn.net/alane1986/article/details/6514000 2010年12月06日 19:20:00 alane1986 阅读数:150 ...

  4. python爬虫-----Python访问http的几种方式

    爬取页面数据,我们需要访问页面,发送http请求,以下内容就是Python发送请求的几种简单方式: 会使用到的库  urllib   requests 1.urlopen import urllib. ...

  5. Vue2.0 中,“渐进式框架”和“自底向上增量开发的设计”这两个概念是什么?(转)

    https://www.zhihu.com/question/51907207?rf=55052497 徐飞 在我看来,渐进式代表的含义是:主张最少. 每个框架都不可避免会有自己的一些特点,从而会对使 ...

  6. MySQL连接

    INNER JOIN(内连接,或等值连接):获取两个表中字段匹配关系的记录. LEFT JOIN(左连接):获取左表所有记录,即使右表没有对应匹配的记录. RIGHT JOIN(右连接): 获取右表所 ...

  7. 题解 CF492C Vanya and Exams

    CF492C Vanya and Exams 有了Pascal题解,来一波C++题解呀qwq.. 简单的贪心题 按b[i]从小到大排序,一个一个学科写直到达到要求即可 #include<cstd ...

  8. Python学习之列表篇

    浮点数类型:round(x,d)可对浮点数进行四舍五入,科学计数法:aeb表示a*10^bpython大小写敏感整数类型:无范围限制,pow(x,y)表示x^y,想算多大算多大,四种表示形式:十进制, ...

  9. 4、maven——构建生命周期

    什么是生命周期? 构建生命周期是一组阶段的序列(sequence of phase),每个阶段定义了目标被执行的顺序,这里的阶段就是生命周期的一部分. 一个典型的Maven生命周期由一些几个阶段的序列 ...

  10. HTML5 canvas自制画板

    找到一个画板的插件,很好用,点击下载  ,页面很简单,但是呢,貌似不适用于手机端,,,