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的个数,求出这个数是多少
代码:
#include<stdio.h>
int num(int n) //求n的阶乘末尾连续0的个数
{ //百度说是定理 记住吧... 5 int ans=0;
6 while(n)
7 {ans+=n/5;
8 n=n/5;
9
10 }
return ans; }
int main()
{
int mid,i=;
int t ,q;
long long l,r;
scanf("%d",&t);
while(t--)
{scanf("%d",&q);
l=;
r=; //r要大于1e8
long long m=;
while(l<=r)
{mid=(l+r)/;
if(num(mid)==q)
{r=mid-;
m=mid;
}
else
{if(num(mid)>q)
r=mid-;
else l=mid+;
} } if(m==) printf("Case %d: impossible\n",i);
else printf("Case %d: %lld\n",i,m);
i++;
}
return ;
}
Trailing Zeroes (III)的更多相关文章
- light oj 1138 - Trailing Zeroes (III)【规律&&二分】
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- 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 ...
- 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 ...
- 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)" ...
- 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 ...
- Trailing Zeroes (III) -;lightoj 1138
Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Y ...
- 1138 - Trailing Zeroes (III) 二分
1138 - Trailing Zeroes (III) You task is to find minimal natural number N, so that N! contains exa ...
随机推荐
- AutoMapper 6.x 扩展方法
简介 很多时候我们使用AutoMapper的时候,都需要进行一个配置才可以使用Mapper.Map<Source,Target>(entity);.如果不进行配置则会报错. 如果实体过多, ...
- KBEngine简单RPG-Demo源码解析(2)
七:服务端资产库文件夹结构http://kbengine.org/cn/docs/concepts/directorys.html看assets, 注意:demo使用的不是默认的assets资产目录, ...
- winform利用委托delegate进行窗体间通信
前段时间学习委托,感觉很模糊的样子,也做过许多实例,但是项目中一直没有用到,今天在项目中遇到一个很简单的例子,现在拿出来,做一个简单的记录. 要求:将弹出框里勾选的内容返回到主面板上. 工具:委托. ...
- rownumber和rowid伪劣用法
select rownum ,deptno,dname loc from dept; select deptno,dname,loc from dept where rownum=1; select ...
- 免费MD5解密网站,轻松破解md5密码,mysql5/mysql323,ntlm,salt密码
md5解密网站:http://cmd5.la 网站语言:php 免费指数:★★★ (8位内小写数字字母免费,11位内数字免费) 解密范围:★★★★☆ (覆盖了1-12位很多常用密码和特殊 ...
- c#Message多功能用法
1. 当要显示如图3个按钮时,并要获得单击不同按钮的进行不同的相应时,可以在MessageBoxButtons后面添加一个.(应该英文的点,此处为了醒目,用中文代替)可以看到提示框下方需要几个按 ...
- 元组-tuple功能介绍
#元组 不可变类型 相当于只读的列表,不可被修改,不可被修改哦 ##创建元组最后加,最后加, 形成良好的习惯 """ tuple() -> empty tuple ...
- set-集合功能介绍
叨逼叨:#集合 不可重复的列表 可变类型#1.添加 无则添加有则不操作 不可重复 # se = {'alex','eric','seven'} # se.add('qiqi') # se.add('b ...
- 学习java应该了解一些html超文本标记语言(前端)
在自己学习的过程中遇到一些内容,怕忘记所以借助博客加深印象也方便查找! html超文本标记语言中,分行级元素和块级元素. 行级元素的含义:行级元素不独占一行,相邻的行级元素在一行排列:行级元素可以控制 ...
- 基于.NET CORE微服务框架 -surging的介绍和简单示例 (开源)
一.前言 至今为止编程开发已经11个年头,从 VB6.0,ASP时代到ASP.NET再到MVC, 从中见证了.NET技术发展,从无畏无知的懵懂少年,到现在的中年大叔,从中的酸甜苦辣也只有本人自知.随着 ...