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. python自动化测试接口测试http请求报404的其中一个坑

    在敲代码的路上 ,总是会遇到报错找半天原因,最后发现是个低级错误的时候! 这不今天为了这个错误找了半天原因.......... http请求接口测试中报404我遇到的大部分都是url的问题: 但是今天 ...

  2. Nginx配置之rewrite、proxy_pass、upstream、location

    如图,这是Nginx的配置文件nginx.conf中的一段配置代码. 在http段中定义了一个名为webservers的upstream模块,主要用于负载均衡. 在server模块中,定义了一个loc ...

  3. CDH平台搭建遇到的问题

    安装之前遇到的问题:   Note: Forwarding request to 'systemctl disable NetworkManager.service'. Removed symlink ...

  4. (一) MySQL架构

    1.MySQL架构 MySQL拥有分层的架构,上层是服务器层的服务和查询执行引擎,下层是存储引擎,真正负责数据的存储和提取. 服务层包含了连接和线程处理,以及大多数MySQL的核心服务,如对SQL的解 ...

  5. ubuntu 虚拟机配置 IP、子网掩码、网关、DNS

    ubuntu 虚拟机配置 IP.子网掩码.网关.DNS 执行 sudo vim /etc/network/interfaces 添加如下配置: auto eth0 iface eth0 inet st ...

  6. 三大浏览器(火狐-谷歌-IE浏览器)驱动版本下载

    1.chrome浏览器: 对于chrome浏览器,有时候会有闪退的情况,有时候也许是版本冲突的问题,我们要对照着这个表来对照查看是不是webdriver和chrome版本不对应 点击下载chrome的 ...

  7. asp.net Swiper 轮播动画

    原文:https://blog.csdn.net/qq_39656138/article/details/90451289 官网:https://www.swiper.com.cn/api/index ...

  8. ASE Alpha Sprint - backend scrum 3

    本次scrum于2019.11.7再sky garden进行,持续10分钟. 参与人: Zhikai Chen, Jia Ning, Hao Wang 请假: Xin Kang, Lihao Ran, ...

  9. tf.trainable_variables和tf.all_variables的对比

    tf.trainable_variables返回的是可以用来训练的变量列表 tf.all_variables返回的是所有变量的列表

  10. 1、获取ip地址

    1.获取ip地址 System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces() .Select(p => p. ...