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

以前在杭电上做过跟这个类似的题,主要考察的知识点一样,只是那个是给出n求0的个数,这个给出0的个数求n

题解:主要还是求数中含有5的个数

#include<stdio.h>
#include<string.h>
#define LL long long
LL fun(LL x)
{
LL ans=0;
while(x)
{
ans+=x/5;
x/=5;
}
return ans;
}
int main()
{
int t,k=1;
LL n;
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n);
LL l=0,r=500000000,mid,ans;
while(r>l)
{
mid=(l+r)/2;
if(fun(mid)>=n)
{
ans=mid;
r=mid;
}
else
l=mid+1;
}
printf("Case %d: ",k++);
if(fun(ans)!=n)
printf("impossible\n");
else
printf("%lld\n",ans);
}
return 0;
}

  

light oj 1138 - Trailing Zeroes (III)【规律&&二分】的更多相关文章

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

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

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

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

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

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

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

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

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

  6. 1138 - Trailing Zeroes (III) 二分

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

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

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

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

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

  9. Trailing Zeroes (III) (二分)题解

    You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in d ...

随机推荐

  1. 关于DataTables一些小结

    最近项目中使用了DataTables,故小结了一下. 导入CSS文件<link rel="stylesheet" href="<%=base %>/js ...

  2. 李洪强iOS开发之OC常见错误汇总

    // //  main.m //  16 - 常见错误汇总 // //  Created by vic fan on 16/7/13. //  Copyright © 2016年 李洪强. All r ...

  3. DNS安全浅议、域名A记录(ANAME),MX记录,CNAME记录(转)

    http://www.cnblogs.com/LittleHann/p/3828927.html 相关学习资料 http://baike.baidu.com/link?url=77B3BYIuVsB3 ...

  4. C++重载输入和输出操作符以及IO标准库中的刷新输入缓冲区残留字符问题

    今天在做C++ Primer习题的14.11时,印象中应该挺简单的一题,结果却费了很长时间. 类定义: typedef string Date; class CheckoutRecord{ publi ...

  5. Spring个人总结

    编写Spring第一个程序 Spring是一种开源框架,通过使用它可以大大降低企业应用程序的复杂性.Spring是一种非常完善的框架,几乎涉及WEB开发中的每一层,但是在开发中通常使用Spring开发 ...

  6. poj2761

    表面上看是主席树之类的区间k大 实际上,除了主席树,还可以测各种结构 因为题目中说,任意区间不会完全包含 于是,我们把区间按左端点排序,依次添加,用平衡树求当前的k大 每个狗最多被添加一次,删除一次 ...

  7. jquery UI Draggable和Droppable 案例

    <html> <head><title>draggable</title> <script type="text/javascript& ...

  8. [POJ 2588] Snakes

    同swustoj 8 Snakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1015   Accepted: 341 ...

  9. Android handler Thread 修改UI Demo

    /********************************************************************** * Android handler Thread 修改U ...

  10. DOM的定义及DOM相关

    DOM : Document Object Model 文档对象模型文档:html页面文档对象:页面中元素文档对象模型:定义 为了能够让程序(js)去操作页面中的元素 DOM会把文档看作是一棵树,同时 ...