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

3

1

2

5

Sample Output

Case 1: 5

Case 2: 10

Case 3: impossible

AC代码

  1. #include<stdio.h>
  2. const int MAXN=0x3f3f3f3f;//这个要足够大才能找到10^8
  3. int getq(int x){
  4. int q=;
  5. while(x){
  6. q+=x/;
  7. x/=;
  8. }
  9. return q;
  10. }
  11. void erfen(int n){
  12. int l=,r=MAXN;
  13. while(l<=r){
  14. int mid=(l+r)>>;
  15. if(getq(mid)>=n)r=mid-;//二分这点注意
  16. else l=mid+;
  17. }
  18. if(getq(l)==n)printf("%d\n",l);
  19. else puts("impossible");
  20. }
  21. int main(){
  22. int T,Q,flot=;
  23. scanf("%d",&T);
  24. while(T--){
  25. scanf("%d",&Q);
  26. printf("Case %d: ",++flot);
  27. erfen(Q);
  28. }
  29. return ;
  30. }

C - Trailing Zeroes (III)(二分)的更多相关文章

  1. 1138 - Trailing Zeroes (III) 二分

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

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

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

  3. C - Trailing Zeroes (III) 二分

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

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

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

  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) 【二分查找好题】【 给出N!末尾有连续的Q个0,让你求最小的N】

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

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

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

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

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

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

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

  10. Trailing Zeroes (III) -;lightoj 1138

    Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Y ...

随机推荐

  1. Office文件的奥秘——.NET平台下不借助Office实现Word、Powerpoint等文件的解析

    Office文件的奥秘——.NET平台下不借助Office实现Word.Powerpoint等文件的解析 分类: 技术 2013-07-26 15:38 852人阅读 评论(0) 收藏 举报 Offi ...

  2. 常见ETL工具一览,你知多少?

    这些年,几乎都与ETL打交道,接触过多种ETL工具.现将这些工具做个整理,与大家分享. 一 ETL工具[国外] 1. datastage点评:最专业的ETL工具,价格不菲,使用难度一般 下载地址:ft ...

  3. yield生成器的经典案例

    如何生成斐波那契數列 斐波那契(Fibonacci)數列是一个非常简单的递归数列,除第一个和第二个数外,任意一个数都可由前两个数相加得到.用计算机程序输出斐波那契數列的前 N 个数是一个非常简单的问题 ...

  4. SpringMVC注解示例

    1.web.xml <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-cla ...

  5. Hibernate错误及解决办法

    1.Hibernate 报错:this project is not a myeclipse hibernate project . assuming hibernate 3 cap res:项目名上 ...

  6. Building Performant Expand & Collapse Animations

    t's starting to be pretty common knowledge that there are only 2 things you can animate cheaply in C ...

  7. JavaUtil_08_StringUtil_commons-lang3 之 StringUtils

    二.参考资料 1.[commons]字符串工具类——commons-lang3之StringUtils

  8. I.MX6 USB Camera

    /************************************************************************* * I.MX6 USB Camera * 说明: ...

  9. 小米5安装Xposed框架——需要解锁刷机

    Xposed官网 https://forum.xda-developers.com/xposed 官方模块厂库 https://repo.xposed.info/ 中文站点 https://xpose ...

  10. SPOJ375Query on a tree I(树剖+线段树)(询问边)

    ιYou are given a tree (an acyclic undirected connected graph) with N nodes, and edges numbered 1, 2, ...