嗯...

题目链接: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. java基础(十一)之抽象类和抽象函数

    1.抽象函数的语法特征2.抽象类的语法特征3.抽象类的作用 抽象函数 只有函数的定义,没有函数体的函数被称为抽象函数: abstract void func(); 抽象类 使用abstract定义的类 ...

  2. 无需QQ成为好友,直接启动QQ客户端聊天

    <a style="color:#fff; margin-left:8px; padding-top:12px;" target="_parent" hr ...

  3. opencv:形态学操作-腐蚀与膨胀

    #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace st ...

  4. 手动搭建的react环境中,关于图片引入的问题

    react手动搭建的环境,require引进来图片不显示,网页src显示[object module] 解决方案 (1)import引进图片 import anli from './img/anli. ...

  5. Linux - XShell - alt 快捷键的设置

    1. 概述 命令行的 alt 快捷键可能会冲突 2. 环境 os win10 centos7 xshell xhell6 3. 场景 开启 centos7 虚拟机 在 win10 打开 xshell6 ...

  6. P2P头部平台退出后,普通人如何避开投资理财的“雷区”?

    编辑 | 于斌 出品 | 于见(mpyujian) 近期,P2P市场上不断传来不利消息,引起市场轩然大波,也打乱了投资者投资计划,是继续坚持自己的选择还是另择它路? 18日,陆金所作为千亿头部平台,宣 ...

  7. Appium-测试失败后获取屏幕截图的方法

    最近一直在研究appium,偶尔的机会发现断言后获取屏幕截图.觉得这个方法不错,分享给大家 这样以后在遇到断言,想截图错误屏幕的时候,能够用的上. 1.首先需要2个类,一个是测试类(TestDropL ...

  8. jenkins和hudson

    自动化构建:Jenkins起源于Hudson.Hudson在商业软件的路上继续前行,而Jenkins则作为开源软件,从hudson分支出来. 因此现在的jenkins和hudson非常类似,但是随着二 ...

  9. 萌新深度学习与Pytorch入门记录(一):Win10下环境安装

    深度学习从入门到入土,安装软件及配置环境踩了不少坑,过程中参考了多处博主给的解决方法,遂整合一下自己的采坑记录. (若遇到不一样的错误,请参考其他博主答案解决) 笔者电脑系统为win10系统,在此环境 ...

  10. PAT 1017 Queueing at Bank (模拟)

    Suppose a bank has K windows open for service. There is a yellow line in front of the windows which ...