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个0。

思路:一个最小的数末尾要出现0一定要是能被5或10整除的,0的连续长度与数组大小正相关,故二分数字得解。

 #include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<limits.h>
#include<algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF=1e9;
typedef unsigned long long ll;
typedef long long LL;
int main()
{
int T,cases=;
scanf("%d",&T);
while(T--)
{
int q;
LL ans=-;
scanf("%d",&q);
int l=,r=q*,mid;//为什么右端点是q*5,因为q*5>=ans.想一想为什么(hint:刚才那个序列。。。)
while(l<=r)
{
mid=(l+r)/;
int m=mid,wu=,count=;
while(m>=wu)
{
int p=m;
p/=wu;
count+=p;
wu*=;
}
if(count==q)
{
ans=mid;
break;
}
else if(count>q)
r=mid-;
else
l=mid+;
}
if(ans==-)
printf("Case %d: impossible\n",cases++);
else
printf("Case %d: %lld\n",cases++,ans/*);
}
}

代码转自(https://blog.csdn.net/duan_1998/article/details/72566106)

Trailing Zeroes (III) LightOJ - 1138 二分+找规律的更多相关文章

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

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

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

  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) 【二分查找 &amp;&amp; N!中末尾连续0的个数】

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

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

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

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

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

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

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

  8. 1138 - Trailing Zeroes (III) 二分

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

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

随机推荐

  1. mybatis-关于<update>的日常记录

    !注意:,一定要有 <update id="updateByPrimaryKeySelective" parameterType="com.dhht.model.o ...

  2. PAT Advanced 1023 Have Fun with Numbers (20) [⼤整数运算]

    题目 Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, ...

  3. 简单总结------redis

    一.Redis 是一个基于内存的高性能key-value数据库. 二.端口 6379 三.特点: Redis本质上是一个Key-Value类型的内存数据库,很像memcached,整个数据库统统加载在 ...

  4. YOLO配置文件理解

    [net] batch=64 每batch个样本更新一次参数. subdivisions=8 如果内存不够大,将batch分割为subdivisions个子batch,每个子batch的大小为batc ...

  5. 学习spring第一天

    Spring第一天笔记   1. 说在前面 怎样的架构的程序,我们认为是一个优秀的架构? 我们考虑的标准:可维护性好,可扩展性好,性能. 什么叫可扩展性好? 答:就是可以做到,不断的增加代码,但是可以 ...

  6. Spring Test+JUnit4整合使用测试ZZJ_淘淘商城项目:day01(RESTful Web Service)

    针对整合的Dao层与Service层,在做spring与通用Mapper和分页插件相关测试时比较麻烦.如果只用JUnit测试,需要每次Test方法里初始化一下applicationContext,效率 ...

  7. Python语言学习前提:基础语法

    一.变量 1.变量:存储数据.存储数据需要对应内存空间,基于变量的数据类型,解释器会分配指定内存,决定什么数据被存储到内存中. 变量数据类型:整数.小数.字符. 2.变量赋值:变量在使用前必须赋值,赋 ...

  8. maven tomcat 自动部署配置

    1:Tomacat 配置 /tomcat-users.xml 添加如下: <role rolename="manager-gui"/> <role rolenam ...

  9. springcloud-netflix组件学习-未完待续!!!

    SpringCloud学习 Spring Cloud是什么鬼? Spring Cloud是一系列框架的有序集合.它利用Spring Boot的开发便利性巧妙地简化了分布式系统基础设施的开发,如服务发现 ...

  10. 897B. Chtholly's request#长度为偶数的回文数(模拟)

    题目出处:http://codeforces.com/problemset/problem/897/B 题目大意:构造一个题意要求的zcy数之后取模 #include<iostream> ...