1138 - Trailing Zeroes (III)
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

题解:这道题要找末尾0的个数所需要的最小阶乘,因为想到10=2*5,然而2是很多数的质因数,数目要大于质因数5的数目,所以只考虑5的质因数的个数,便为末尾0的个数,所以

int q=0;
while(x){
q+=x/5;
x/=5;
}

这点便可以得出x!末尾0的个数;

用二分,从无穷大开始找,找到Q就是答案;

代码:

 #include<stdio.h>
const int MAXN=0x3f3f3f3f;//这个要足够大才能找到10^8
int getq(int x){
int q=;
while(x){
q+=x/;
x/=;
}
return q;
}
void erfen(int n){
int l=,r=MAXN;
while(l<=r){
int mid=(l+r)>>;
if(getq(mid)>=n)r=mid-;//二分这点注意
else l=mid+;
}
if(getq(l)==n)printf("%d\n",l);
else puts("impossible");
}
int main(){
int T,Q,flot=;
scanf("%d",&T);
while(T--){
scanf("%d",&Q);
printf("Case %d: ",++flot);
erfen(Q);
}
return ;
}

Trailing Zeroes (III)(lightoj 二分好题)的更多相关文章

  1. LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)

    http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS     M ...

  2. 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 ...

  3. Light oj 1138 - Trailing Zeroes (III) 【二分查找 &amp;&amp; N!中末尾连续0的个数】

    1138 - Trailing Zeroes (III) problem=1138"> problem=1138&language=english&type=pdf&q ...

  4. 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 ...

  5. lightoj 1138 - Trailing Zeroes (III)【二分】

    题目链接:http://lightoj.com/volume_showproblem.php? problem=1138 题意:问 N. 末尾 0 的个数为 Q 个的数是什么? 解法:二分枚举N,由于 ...

  6. 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! ...

  7. Trailing Zeroes (III) LightOJ - 1138 不找规律-理智推断-二分

    其实有几个尾零代表10的几次方但是10=2*510^n=2^n*5^n2增长的远比5快,所以只用考虑N!中有几个5就行了 代码看别人的: https://blog.csdn.net/qq_422797 ...

  8. Trailing Zeroes (III) (二分)题解

    You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in d ...

  9. 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 ...

随机推荐

  1. 新手讲树:证明任意二叉树度为零的节点n0,永远比度为2的节点n2多1个

    证明:   设度为1的节点个数为n1,因为二叉树的所有节点的度都小于等于2, 所以n=n0+n1+n2; 又因为二叉树中,除了根节点所有的节点都有一个进入节点的分支,假设B为所有的分支,那么n=B+1 ...

  2. Cordova+Asp.net Mvc+GIS

    Cordova+Asp.net Mvc+GIS跨平台移动应用开发实战1-系统初步搭建(附演示,apk,全部源码)   1.前言 身处在移动互联网的今天,移动应用开发炙手可热,身为程序猿的我们怎么能错过 ...

  3. jquery.lazyload.js图片延迟加载(懒加载)--转载

    一.插件介绍 jquery.lazyload.js 是一个用 JavaScript 编写的jQuery 插件. 它可以延迟加载长页面中的图片. 在浏览器可视区域外的图片不会被载入, 直到用户将页面滚动 ...

  4. LGA(land grid array)

    产品应用 1.射频功放 2.加速度传感器 3.地磁传感器 可靠性 Reliability 高压蒸煮 PCT 121℃,100%RH,2atm,96hrs 高低温循环 TCT -55℃(15min)~1 ...

  5. 利用 Windows Azure 实现“云优先”

    根据 IDC 的调查,云计算无疑为我们的合作伙伴提供了巨大的机会,预计到 2016 年,全球企业将在公共云服务上耗资 980 亿美元.在今天的休斯敦全球合作伙伴大会上,我们非常高兴能与合作伙伴共同寻求 ...

  6. #include <mutex>

    多线程初级 #include <iostream> #include <thread> #include <windows.h> #include <mute ...

  7. c++ string.find()函数的陷阱

    string.find(char *)查找字符串中是否包含子串 找到:返回第一个索引 没有找到:返回一个很大的随机数字而不是返回负数(这是个坑) 所以不能这么写if (string.find(str) ...

  8. Yii中的CCheckBoxColumn在widget中的用法

    'columns'=>array(        array(            'class'=>'CCheckBoxColumn',            'id'=>'us ...

  9. 得到当前网址的域名 ASP.NET

    HttpContext.Current.Request.Url.Host.ToString(); http://"是协议名 "www.test.com"是域名 " ...

  10. javaScript 工作必知(三) String .的方法从何而来?

    String 我们知道javascript 包括:number,string,boolean,null,undefined 基本类型和Object 类型. 在我的认知中,方法属性应该是对象才可以具有的 ...