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

题意:

  给出一个Q,求出最小的n的阶乘的末尾0(后导)的个数为Q 。

思路:

  0是由2*5组成的,也就是相当于一个偶数乘上一个5的倍数,而偶数肯定是跟在5的前面的,所以只需要求出5的倍数(包括5)的个数即可。

注意:

  N的范围、求的是最小的N(需要取区间左边)

 #include<stdio.h>
#include<iostream>
const int N=;
using namespace std; int findzero(int x)
{
int sum=;
while(x)
{
sum=sum+x/;
x=x/;
}
return sum;
} int erfen(int x)
{
int L=,R=N,mid;
while(L<=R)
{
mid=L+((R-L)>>);
if(findzero(mid)<x)
{
L=mid+;
}
else
{
R=mid-;
}
// else if(findzero(mid)==x)
// {
// return L;
// }
}
if(findzero(L)==x)
return L;
return ;
} int main()
{
int n,tt=,t,q;
scanf("%d",&t);
while(t--)
{
scanf("%d",&q);
int ans=erfen(q);
if(ans==)
printf("Case %d: impossible\n",tt++);
else
printf("Case %d: %d\n",tt++,ans); }
return ;
}

最新文章

  1. C#开发系统服务时用的定时器组件
  2. HTML5火焰文字特效DEMO演示---转载
  3. 利用jQuery和Ajax实现检测用户名是否已经被注册
  4. OVS ARP Responder – Theory and Practice
  5. How to generate number Sequence[AX 2012]
  6. [改善Java代码]对字符串排序 持一种宽容的心态
  7. FragmentActivity和Activity的具体区别在哪里
  8. zoj 3351 Bloodsucker(概率 dp)
  9. 强制转https
  10. JAVA邮件收发实现(待)
  11. php在客户端禁用cookie时让session不失效的解决方法
  12. 用Python删除本地目录下某一时间点之前创建的所有文件
  13. codechef [snackdown2017 Onsite Final] Fusing Weapons
  14. Jetson TX2上的demo(原创)
  15. AJAX的简洁写法
  16. 学习ASP.NET Core Razor 编程系列十二——在页面中增加校验
  17. gitlab搭建
  18. TCP学习总结(一)
  19. 一些常见的Java面试题 &amp; 面试感悟
  20. Visual Studio 代码快捷键

热门文章

  1. js排他功能示例
  2. Vue for循环 例子
  3. bzoj1059题解
  4. delphi mysql
  5. kafka保证数据不丢失机制
  6. NX二次开发-UFUN将建模绝对空间中的点映射到工程图坐标UF_VIEW_map_model_to_drawing
  7. (转)Android 创建与解析XML—— Dom4j方式 .
  8. 内置Jetty配置JSP支持过程中的常见报错
  9. 002-Java数据类型
  10. 2018自己的JavaScript开发指南