Trailing Zeroes (III) LightOJ - 1138 二分+找规律
Time Limit: 2 second(s) | Memory Limit: 32 MB |
You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in decimal notation. As you know N! = 1*2*...*N. For example, 5! = 120, 120 contains one zero on the trail.
Input
Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case contains an integer Q (1 ≤ Q ≤ 108) in a line.
Output
For each case, print the case number and N. If no solution is found then print 'impossible'.
Sample Input |
Output for Sample Input |
3 1 2 5 |
Case 1: 5 Case 2: 10 Case 3: impossible |
题意:求出现一个最小的数的阶乘满足末尾有连续q个0。
思路:一个最小的数末尾要出现0一定要是能被5或10整除的,0的连续长度与数组大小正相关,故二分数字得解。
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<limits.h>
#include<algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF=1e9;
typedef unsigned long long ll;
typedef long long LL;
int main()
{
int T,cases=;
scanf("%d",&T);
while(T--)
{
int q;
LL ans=-;
scanf("%d",&q);
int l=,r=q*,mid;//为什么右端点是q*5,因为q*5>=ans.想一想为什么(hint:刚才那个序列。。。)
while(l<=r)
{
mid=(l+r)/;
int m=mid,wu=,count=;
while(m>=wu)
{
int p=m;
p/=wu;
count+=p;
wu*=;
}
if(count==q)
{
ans=mid;
break;
}
else if(count>q)
r=mid-;
else
l=mid+;
}
if(ans==-)
printf("Case %d: impossible\n",cases++);
else
printf("Case %d: %lld\n",cases++,ans/*);
}
}
代码转自(https://blog.csdn.net/duan_1998/article/details/72566106)
Trailing Zeroes (III) LightOJ - 1138 二分+找规律的更多相关文章
- Trailing Zeroes (III) LightOJ - 1138 不找规律-理智推断-二分
其实有几个尾零代表10的几次方但是10=2*510^n=2^n*5^n2增长的远比5快,所以只用考虑N!中有几个5就行了 代码看别人的: https://blog.csdn.net/qq_422797 ...
- Trailing Zeroes (III) LightOJ - 1138(二分)
You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in d ...
- Trailing Zeroes (III)(lightoj 二分好题)
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 ...
- LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)
http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS M ...
- light oj 1138 - Trailing Zeroes (III)【规律&&二分】
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- LightOJ Trailing Zeroes (III) 1138【二分搜索+阶乘分解】
1138 - Trailing Zeroes (III) PDF (English) problem=1138" style="color:rgb(79,107,114)" ...
- 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) 【二分查找好题】【 给出N!末尾有连续的Q个0,让你求最小的N】
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...
随机推荐
- 基于JSP+Servlet新闻发布系统 源码
开发环境: Windows操作系统开发工具: Eclipse+Jdk+Tomcat+MYSQL数据库 运行效果图:
- Scanner方式输入小写字母转换成大写字母
import java.util.Scanner; /** * 小写字母转换成大写字母 * @author zzu119 * */ public class letterTransfe ...
- rpc框架解释
远程过程调用协议RPC(Remote Procedure Call Protocol) RPC是指远程过程调用,也就是说两台服务器A,B,一个应用部署在A服务器上,想要调用B服务器上应用提供的函数/方 ...
- c语言中多维数组和指针的关系
如图: 执行结果: 说明:由执行结果可知,三个输出的结果相等(可能在不同的平台执行结果不相同,但三个的结果是相等的),数组multi的地址与数组multi[0]的地址相同,都等于存储的第一个整数的地址 ...
- 项目部署篇之——下载安装Xftp6,Xshell6
俗话说工欲善其事必先利其器,想要在服务器上部署环境就得先安装操作工具. 我用的是xshell6,和xftp6.下面是下载连接,都是免费版的,不需要破解 xftp6链接:https://pan.baid ...
- 分享一套好看的PyCharm Color Shceme 配色方案
配色方案图1 点击可查看大图 (color shceme 配色文件下载链接已经放在文末) 配色方案图2 配色方案图3 picture1 picture2 整体效果 下载链接 https://files ...
- 推荐:MongoDB学习资料
http://www.mongodb.org/display/DOCS/Production+Deployments Official MongoDBProject Website Getting S ...
- C#匿名委托,匿名函数,lambda表达式
一.类型.变量.实例之间的关系. 类型>变量>实例 类型可以创建变量,实体类可以创建实例,实例可以存储在变量里. 二.委托使用过程: 1.定义委托(写好签名): 2.创建委托变量: 3.给 ...
- python处理nii格式文件
网上已经有很多代码了,但是注释的都不全,看起来很费解,我自己加了一些注释,重新发出来,尽可能的通俗易懂 读取前需要先安装库 pip install nibabel pip install matplo ...
- JQ和JS的等价代码
JQ与JS等价代码 选择器 //jquery var els = $(".el"); //原生方法 var els = document.querySelectorAll(&q ...