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


题意:给你一个数Q。代表N!中末尾连续0的个数。让你求出最小的N。

求N!中尾连续0的个数:

LL change(LL x){
LL ans = 0;
while(x){
ans += x / 5;
x /= 5;
}
return ans;
}

AC代码

#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
#define INF 0x3f3f3f3f
#define LL long long LL change(LL x){
LL ans = 0;
while(x){
ans += x / 5;
x /= 5;
}
return ans;
} int main (){
int T, n;
int k = 1;
scanf("%d", &T);
while(T--){
scanf("%d", &n);
LL l = 0, r = 100000000 * 5 + 10;
LL mid, ans;
while(r > l){
mid = (l + r) / 2;
if(change(mid) >= n){
ans = mid;
r = mid;
}
else
l = mid + 1;
}
printf("Case %d: ", k++);
if(change(ans) == n)
printf("%lld\n", ans);
else
printf("impossible\n"); }
return 0;
}

Light oj 1138 - Trailing Zeroes (III) 【二分查找 &amp;&amp; N!中末尾连续0的个数】的更多相关文章

  1. Light oj 1138 - Trailing Zeroes (III) (二分)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N. 我们可以知 ...

  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)【规律&&二分】

    1138 - Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit:  ...

  4. 1138 - Trailing Zeroes (III) 二分

    1138 - Trailing Zeroes (III)   You task is to find minimal natural number N, so that N! contains exa ...

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

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

  6. LightOj 1138 - Trailing Zeroes (III) 阶乘末尾0的个数 & 二分

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题意:给你一个数n,然后找个一个最小的数x,使得x!的末尾有n个0:如果没有输出 ...

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

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

  8. LightOj 1138 Trailing Zeroes (III)

    题目描述: 假设有一个数n,它的阶乘末尾有Q个零,现在给出Q,问n最小为多少? 解题思路: 由于数字末尾的零等于min(因子2的个数,因子5的个数),又因为2<5,那么假设有一无限大的数n,n= ...

  9. LightOJ 1138 Trailing Zeroes (III) 打表

    就是统计5,然后当时因为发现最多有8000w个5的倍数,然后8000w/100,是80w,打表,二分找 然后我看网上的都是直接二分找,真是厉害 #include <cstdio> #inc ...

随机推荐

  1. python django简单操作

    准备: pip3 install  django==1.10.3 cmd django-admin startproject  guest  创建一个guest的项目 cd guest manage. ...

  2. mariadb的安装

    mysql (分支 mariadb)1.安装mariadb -yum -源码编译安装 -下载rpm安装 yum和源码编译安装的区别? 1.路径区别-yum安装的软件是他自定义的,源码安装的软件./co ...

  3. Java系列学习(四)-运算计算

    1.运算符 (1)算术运算符 A:+,-,*,/,%,++,-- B:+的用法 [a.加法] [b.正号] [c.字符串连接付] C:/和%的区别 [数据做除法的时候,/取的是商,%取的是余数] D: ...

  4. mysql简单增删改查(CRUD)

    先描述一下查看表中所有记录的语句以便查看所做的操作(以下所有语句建议自己敲,不要复制以免出错): user表,字段有 id, name,age,sex:id为主键,自增,插入时可以写 NULL 或者 ...

  5. 最容易理解的CSS的position教程——十步图解CSS的position

    CSS的positon,我想做为一个Web制作者来说都有碰到过,但至于对其是否真正的了解呢?那我就不也说了,至少我自己并不非常的了解其内核的运行.今天在Learn CSS Positioning in ...

  6. css每次的初始化代码

    ;;} body{font-size:14px;} img{border:none;} li{list-style:none;} input,select,textarea{outline:none; ...

  7. 利用php生成验证码

    <?php /** * php生成验证码 * @param $width 画布宽 * @param $height 画布高 * @param $vcodelen 验证码长度 * @param $ ...

  8. 【技术累积】【点】【java】【23】super以及重写重载

    重写和重载 重写是继承之后的Override 重载是同一个方法,有着不同的入参出参这样子: super 当需要在子类中调用父类的被重写方法时,要使用super关键字. 当然只要是调用父类的方法,都会用 ...

  9. swift class protocol-限定协议只能由类实现

    protocol GameMode:class “You can limit protocol adoption to class types (and not structures or enume ...

  10. js 判断 微信浏览器

    <script type="text/javascript"> window.onload = function() { isWeixinBrowser(); } // ...