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


PROBLEM SETTER: JANE ALAM JAN
题意:如果某个数的阶乘有n个0,问这个数最小可以是多少。

题目描述:

  假设有一个数n,它的阶乘末尾有Q个零,现在给出Q,问n最小为多少?

解题思路:

  由于数字末尾的零等于min(因子2的个数,因子5的个数),又因为2<5,那么假设有一无限大的数n,n=2^x=5^y,可知x<<y。

所以我们可以直接根据因子5的个数,算阶乘末尾的零的个数。1<=Q<=10^8,所以可以用二分快速求解。

代码:

 #include<iostream>
#include<cstdio>
#include<cstring> using namespace std; long long slove(long long n)
{
long long ans = ;
while(n)
{
ans += n/;
n /= ;
}
return ans;
} int main()
{
int t, l = ; scanf("%d", &t);
while(t--)
{
long long n;
scanf("%lld", &n);
long long mid, low = , high = ; while(low <= high) // 二分查找快~
{
mid = (low+high)/;
long long num = slove(mid);
if(num >= n)
high = mid-;
else
low = mid+;
}
if(slove(low) == n)
printf("Case %d: %lld\n", l++, low);
else
printf("Case %d: impossible\n", l++);
}
return ;
}

Trailing Zeroes (III) -;lightoj 1138的更多相关文章

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

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

  2. LightOJ Trailing Zeroes (III) 1138【二分搜索+阶乘分解】

    1138 - Trailing Zeroes (III) PDF (English) problem=1138" style="color:rgb(79,107,114)" ...

  3. Trailing Zeroes (III)(lightoj 二分好题)

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

  4. light oj 1138 - Trailing Zeroes (III)【规律&&二分】

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

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

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

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

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

  8. 1138 - Trailing Zeroes (III) 二分

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

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

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

随机推荐

  1. oracle 11g 数据库恢复技术 ---02 控制文件

    oracle 11g 数据库恢复技术 ---02 控制文件 SYS@ orcl >show parameter control_file NAME TYPE VALUE ------------ ...

  2. centos 6.5 升级openssh-7.5

    1.环境 2.安装telnet 服务,防止ssh升级之后登陆不上服务器,使用telnet 连接服务器 yum install telnet-server -y chkconfig telnet on ...

  3. Git的资源地址

    下载地址:https://git-scm.com/downloads 安装教程: https://baijiahao.baidu.com/s?id=1619087367741781687&wf ...

  4. node+express 中安装nodemon实时更新server.js

    每次启动node server.js,有一个缺点,每次server.js文件有改动时,必须重新执行指令node server.js,新的代码才会起作用 解决方案1 全局安装 npm install s ...

  5. charles_02_模拟弱网测试

    前言 用户使用app的场景是多变的,不一定稳定在WiFi或者4G网络下.大多数用户会在地铁.电梯等弱网情况下使用app,这些弱网情况下app常会出现一些数据丢失.闪退.页面展示不友好等情况.在测试过程 ...

  6. ecshop注册用户增加手机验证功能

    1.去掉“用户名”注册 a.去掉提交 user_passport.dwt页面去掉 <input name="username" type="text" s ...

  7. [集合]List

    List 存取有序,有索引,可以重复 ArrayList去除集合中字符串的重复值(字符串的内容相同) public static void main(String[] args) { ArrayLis ...

  8. python学习第四十六天dir( )函数用法

    dir( )函数有点像目录的意思,但是他是包含由模块定义的名称的字符串的排序列表.这个列表包含模块中定义的所有模块,变量和函数的名称. 列举其用法 import time content = dir( ...

  9. 第7章 PTA查找练习题

    这道题与第7章查找有关,当时提前看到,翻到书里面的算法,然后打进去,虽然是正确的,但是那时候并不知道二叉排序树的基础知识,包括插入查找的来龙去脉,现在已经学到了,有了一定了解,发现题目只用到了其中部分 ...

  10. k3 cloud支付申请单下推付款单时候提示未将对象引用设置到对象的实例

    项目支付申请部门没有币别没有填写,没有把币别带过来才