C - Trailing Zeroes (III) 二分
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
3
1
2
5
Sample Output
Case 1: 5
Case 2: 10
Case 3: impossible
其实我特别反感这种思维题目,感觉没别的方法,没什么意思,只能这样写,还有就是我太菜了(这才是原罪)
思路::有几个0出现关键就看2和5的个数,因为是阶乘,都是乘法运算,所有要将没一个数拆开,看看他包括几个2或者几个5,,比如,10 可以分为2和5,所以只有1个5,而
25可以分为5和5 所以有两个5。。。。。在一组数中,二的数目一定比5 多吗,所以直接找5 的个数就可以啦!
记得设置为long long
AC代码:
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll sum(ll x){
ll ans=;
while(x)
{
ans+=x/;
x=x/;
}
return ans;
} int main()
{
int t;
scanf("%d",&t);
for(int i=;i<=t;i++)
{
ll n;
scanf("%lld",&n);
ll left=,right=,ans=,mid;
while(left<=right)
{
mid=(left+right)/;
if(sum(mid)==n){
ans=mid;
right=mid-;
}//找到了不一定是最小的比如11和10,阶乘都可以产生2个0
else if(sum(mid)>n){
right=mid-;
}
else {
left=mid+;
}
} if(ans>)
printf("Case %d: %lld\n",i,ans);
else
{
printf("Case %d: impossible\n",i);
}
}
return ;
}
C - Trailing Zeroes (III) 二分的更多相关文章
- 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) (二分)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N. 我们可以知 ...
- Trailing Zeroes (III)(lightoj 二分好题)
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- 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) 【二分查找好题】【 给出N!末尾有连续的Q个0,让你求最小的N】
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...
- light oj 1138 - Trailing Zeroes (III)【规律&&二分】
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 Trailing Zeroes (III) 1138【二分搜索+阶乘分解】
1138 - Trailing Zeroes (III) PDF (English) problem=1138" style="color:rgb(79,107,114)" ...
- Trailing Zeroes (III) -;lightoj 1138
Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Y ...
随机推荐
- 【2019HDU多校】第九场1006/HDU6685-Rikka with Coin——位运算打表
题目链接 题目大意 使用10.20.50.100元面额的硬币能分别组成题目给出的面额,需要最少的硬币个数 分析 一开始队友想用一堆if-else解决问题,然后WA了无数发-- 我想到了一种比较简单的打 ...
- 解决 Mac Android Studio Gradle Sync 慢的问题
1.启动Android Studio 2.从项目的 gradle/wrapper/gradle-wrapper.properties 目录中找到 distributionUrl 这个字段,查看后面对应 ...
- MQ的理论理解
MQ(消息队列)简介 概念 : 消息队列(MQ)是一种应用程序对应用程序的通信方法. 应用程序通过写和检索出入列队的针对应用程序的数据(消息)来通信,而无需专用连接来链接它们. 消息传递指的是程序之间 ...
- 使用DeepWalk从图中提取特征
目录 数据的图示 不同类型的基于图的特征 节点属性 局部结构特征 节点嵌入 DeepWalk简介 在Python中实施DeepWalk以查找相似的Wikipedia页面 数据的图示 当你想到" ...
- Java&Spring过时的经典语录
字符串拼接:请用StringBuffer代替String直接相加提高性能 过去的理论 有没有人告诉过你开发中不要 String newString = "牛郎"+"织 ...
- Java并发编程锁之独占公平锁与非公平锁比较
Java并发编程锁之独占公平锁与非公平锁比较 公平锁和非公平锁理解: 在上一篇文章中,我们知道了非公平锁.其实Java中还存在着公平锁呢.公平二字怎么理解呢?和我们现实理解是一样的.大家去排队本着先来 ...
- VRRP协议:Virtual Route
VRRP协议:Virtual Route Redundancy Protocol虚拟路由冗余协议.是一种容错协议,保证当主机的下一跳路由出现故障时,由另一台路由器来代替出现故障的路由器进行工作,从而 ...
- 写给小白看的入门级 Java 基本语法,强烈推荐
之前写的一篇我去阅读量非常不错,但有一句留言深深地刺痛了我: 培训班学习半年,工作半年,我现在都看不懂你这篇文章,甚至看不下去,对于我来说有点深. 从表面上看,这句话有点讽刺我的文章写得不够通俗易懂的 ...
- Python第三方包之离线安装
Python第三方包之离线安装 第一步 首先我们得从pypi上先下载要装的第三方包 https://pypi.org/ 第二步(因为下载下来的包可能需要其他包的依赖,那我们依旧要按照第一步再次下载) ...
- P1343 地震逃生(最大流板题)
P1343 地震逃生 题目描述 汶川地震发生时,四川**中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点,m条边.1号点为教室,n号点为安全地带, ...