Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Description

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

题意:寻找最小的自然数N,使其阶乘的末尾有Q个0.
思路:只有2和5相乘时末尾才会出现0,在阶乘过程中,因子2的个数足够多,所以每遇到一个5,末尾就会出现一个0,因此问题转化为求1到N这N个整数中包含了多少个因子5。
#include<stdio.h>
#include<string.h>
#define MAX 0x3f3f3f
#define LL long long
LL fun(LL x)
{
LL ans=0;
while(x)
{
ans+=x/5;
x=x/5;
}
return ans;
}
int main()
{
int n,k=1;
LL m;
scanf("%d",&n);
while(n--)
{
scanf("%lld",&m);
LL left=0;
LL right=400000010;
LL mid;
while(left<=right)
{
mid=(left+right)>>1;
if(fun(mid)>=m)
right=mid-1;
else
left=mid+1;
}
printf("Case %d: ",k++);
if(fun(left)!=m)
printf("impossible\n");
else
printf("%lld\n",left);
}
return 0;
}

  

light oj 1138的更多相关文章

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

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

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

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

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

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

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

  5. (二分搜索 数论)(求阶乘里零个数对应的阶乘)light oj -- 1138

    链接 Description You task is to find minimal natural number N, so that N! contains exactly Q zeroes on ...

  6. Light OJ 1114 Easily Readable 字典树

    题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...

  7. Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖

    题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...

  8. Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖

    标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...

  9. Light OJ 1316 A Wedding Party 最短路+状态压缩DP

    题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...

随机推荐

  1. [Ruby on Rails系列]2、开发环境准备:Ruby on Rails开发环境配置

    前情回顾 上次讲到Vmware虚拟机的安装配置以及Scientific Linux 6.X系统的安装.这回我们的主要任务是在Linux操作系统上完成Ruby on Rails开发环境的配置. 在配置环 ...

  2. 【转】linux C++ 获取文件信息 stat函数详解

    stat函数讲解 表头文件:    #include <sys/stat.h>             #include <unistd.h>定义函数:    int stat ...

  3. R语言笔记:快速入门

    1.简单会话 > x<-c(1,2,4) > x [1] 1 2 4 R语言的标准赋值运算符是<-.也可以用=,不过不建议用它,有些情况会失灵.其中c表示连接(concaten ...

  4. Scrapy在win7 32位的安装及依赖包

    Scrapy,一个网络爬虫的框架,首先第一步肯定是安装. 参考网上的文章. 安装过程中需要用到pip工具,请自行安装. 1.安装python 这个是必须的,既然都用到scrapy了,肯定已经安装了py ...

  5. 实用的eclipse adt 快捷键

    Ctrl + Shift + T: 打开类型:显示"打开类型"对话框来在编辑器中打开类型."打开类型"选择对话框显示工作空间中存在的所有类型如类.接口等.    ...

  6. Ubuntu安装node.js

    通过PPA安装Node.js sudo apt-get install python-software-properties sudo add-apt-repository ppa:chris-lea ...

  7. UVa 1152 (中途相遇法) 4 Values whose Sum is 0

    题意: 要从四个数组中各选一个数,使得这四个数之和为0,求合法的方案数. 分析: 首先枚举A+B所有可能的值,排序. 然后枚举所有-C-D的值在其中用二分法查找. #include <cstdi ...

  8. iOS application: how to clear notifications?

    http://stackoverflow.com/questions/8682051/ios-application-how-to-clear-notifications up vote105down ...

  9. 自适应的CSS代码片段(常用)

    /* Smartphones (portrait and landscape) ----------- */ @media only screen and (min-device-width : 32 ...

  10. Hibernate4.x之Session--常用方法

    接上篇文章继续学习Hibernate的Session(http://www.cnblogs.com/dreamfree/p/4111777.html) 持久化对象的状态; 站在持久化的角度,Hiber ...