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 ...
随机推荐
- hdu1213 并查集板子
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1213/ 并查集是一种支持合并与查找的数据结构,在森林中进行操作,加上路径压缩,合并和查找的时间复杂度几乎都是常数 ...
- 一个使用fasttext训练的新闻文本分类器/模型
fastext是什么? Facebook AI Research Lab 发布的一个用于快速进行文本分类和单词表示的库.优点是很快,可以进行分钟级训练,这意味着你可以在几分钟时间内就训练好一个分类模型 ...
- 检测页面是否允许使用Flash
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ssm整合配置文件
web.xml: <!-- 指定spring的配置文件的路径和名称 --> <context-param> <param-name>contextConfigLoc ...
- 手把手教你学Git
Git 使用手册独家实战 0.查看本机公钥 步骤: 1.进入.ssh目录 cd ~/.ssh 2.找到id_rsa.pub文件 ls / ll 3.查看文件 cat id_rsa.pub JackFe ...
- Python NLP库top6的介绍和比较
文章来源:ActiveWizards https://medium.com/activewizards-machine-learning-company/comparison-of-top-6-pyt ...
- 【转载】卸载Anaconda教程
文章来源:https://docs.continuum.io/anaconda/install/uninstall/ 卸载Anaconda 要卸载Anaconda,您可以简单地删除该程序.这将留下一些 ...
- Oracle12C的卸载过程
1.找到自己的Oracle12C安装目录,一般的安装目录为D:\app\u01\product\12.1.0\dbhome_1\deinstall ,双击deintall.dat文件进行卸载. 2.耐 ...
- 17.用cmd创建maven web工程
1.跳转到需要创建maven工程的目录,输入 mvn archetype:generate 2.找到webapp的那一项,输入它的序号(这里是10) 3.输入groupId,artifactId,ve ...
- 《java编程思想》一切都是对象
1. 用引用操纵对象 在Java中一切皆对象,我们平常在对java中的类进行操作时,其实操作的不是对象本身而是对象的引用.我们可以将这想象成用遥控器(引用)操作电视机(对象),只要握住这个遥控器,就能 ...