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. 接口自动化之get/post请求

    本篇旨在对get和post请求做一个总结 目录 1.get请求 2.post请求 1.get请求 get请求一般形式相同,仅带url即可发送请求 对于https协议的请求,加一个特殊处理即可(veri ...

  2. Delphi控件-复合控件

     http://blog.csdn.net/cml2030/article/details/3166634 Delphi控件-复合控件 标签: delphidestructorbuttonstring ...

  3. spring-data-elasticsearch使用出现的一些小问题

    问题一failed to load elasticsearch nodes : org.elasticsearch.index.mapper.MapperParsingException: No ty ...

  4. review-1

    # ### for 循环和序列的运用 # remember = ['从入门到放弃', '从入门到如土', 123, 'happy']# for each in remember:# print(eac ...

  5. 剑指offer--day07

    1.1 题目:反转链表:输入一个链表,反转链表后,输出新链表的表头. 1.2 思路:这道题,我们要做到的是反转链表,我们的思路是将前一个节点与后一个节点断开,然后让后一个节点指向前一个节点,这个过程就 ...

  6. 触摸板PCB制作-TM12

    1.布局: 使 PSoC 与Sensor之间的距离保持最小化是一个不错的做法. 通常将 PSoC 与其他组件一起贴装到底层,而将 CapSense Sensor置于顶层上.  Sensor和栅格地层位 ...

  7. Java判断一个日期是否在下周日期区间

    Java实现判断一个日期是否在下周日期区间的方法 /** * 判断输入的日期是否在下周区间 * @return * @author nemowang */ public static boolean ...

  8. Excel VBA在生成副本的工作表中插入本工作簿中的VBA模块代码

    即在工作簿中添加一个工作表,然后移出并存为新的工作簿,在移出前将本工作簿的一个模块的代码拷贝至新的工作簿.下面是关键代码: '===================================== ...

  9. postgresql 口令: psql: 致命错误: 用户 认证失败

    在Windows环境下使用psql 命令出现认证失败. 网上找了很多,都没讲到要点 D:\program\PostgreSql\bin>psql口令: psql: 致命错误: 用户 " ...

  10. A.Gennady and a Card Game

    http://m3.codeforces.com/contest/1097/problem/A Gennady and a Card Game time limit per test 1 second ...