嗯...

题目链接: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. 搭建FEBS权限系统

    在码云看到一个FEBS权限系统,但是没有找到搭建手册,自己记录一下. 1.下载项目:https://github.com/wuyouzhuguli/FEBS-Shiro2.创建数据库:执行sql文件夹 ...

  2. 通过scrapy,从模拟登录开始爬取知乎的问答数据

    这篇文章将讲解如何爬取知乎上面的问答数据. 首先,我们需要知道,想要爬取知乎上面的数据,第一步肯定是登录,所以我们先介绍一下模拟登录: 先说一下我的思路: 1.首先我们需要控制登录的入口,重写star ...

  3. HTML5圆形百分比进度条插件circleChart

    在页面中引入jquery和circleChart.min.js文件. <script src="path/to/jquery.min.js"></script&g ...

  4. 关于java中MD5加密(可直接使用)

    本文转自:http://www.cnblogs.com/solove/archive/2011/10/18/2216715.html 上部分是转载的关于字符串的加密,后半部分则比较全,包括字符串.文件 ...

  5. oracle-数据库被注入恶意攻击程序的案例恢复

    问题描述: Oracle数据库由于重启之后无法正常启动,tab$被清空(ORA-600 16703故障解析—tab$表被清空),导致数据库启动异常 ORA-600 16703报错 一.检测方法: 如下 ...

  6. 动态设置 layui select 为选中状态

    // 当前的select的id $('#type').val('你的value值'); //更新全部 layui.form.render();

  7. 详解Django中Request对象的相关用法

    原文链接:http://www.jb51.net/article/69624.htm 1.从Request对象中获取数据 我们在第三章讲述View的函数时已经介绍过HttpRequest对象了,但当时 ...

  8. .NET Core部署Windows服务

    创建 首先你要确保你已经安装了.NET Core 3.0或以上版本. 老版本的Windows服务请看 这篇文章 使用命令行创建:  dotnet new worker 使用Visual Studio创 ...

  9. JAVA(4)之关于项目部署在tomcat

    关于项目部署的报错问题一直是找不到项目 在重装几次tomcat9和tomcat7后找到了原因,关键原因是访问路径不正确,项目名拼写错误. 排除问题的思路如下(控制变量法) 工作方法和思路 列出步骤,从 ...

  10. Codeforces Round #601 (Div. 2)E(寻找质因子,DP)

    先分解质因数,对于当前a[i],假设当前的质因数为x,这个位置要满足能被k整除,有两个可能,要么是它向后一个转移x%k个,要么是后一个向它转移k-x%k个. 对于每一个a[i]满足后,因为只会对下一个 ...