链接

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

代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std; #define N 0x3f3f3f3f int Num0(int n)
{
int sum = ; while(n)
{
sum += n/;
n /= ;
}
return sum;
} void Search(int w) ///二分搜索
{
int L=, R=N, mid; while(L<=R)
{
mid = (L+R)>>; if(w <= Num0(mid))
R = mid - ;
else
L = mid + ;
} if(Num0(L)==w)
printf("%d\n", L);
else
printf("impossible\n");
} int main()
{
int iCase=, n, t;
scanf("%d", &t);
while( t-- )
{
scanf("%d", &n); printf("Case %d: ", iCase++);
Search(n);
}
return ;
}

(二分搜索 数论)(求阶乘里零个数对应的阶乘)light oj -- 1138的更多相关文章

  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. AJPFX:不用递归巧妙求出1000的阶乘所有零和尾部零的个数

    package com.jonkey.test; import java.math.BigInteger; public class Test6 { /*** @param args*  需求:求出1 ...

  4. Codeforces Round #538 (Div. 2) C 数论 + 求b进制后缀零

    https://codeforces.com/contest/1114/problem/C 题意 给你一个数n(<=1e8),要你求出n!在b进制下的后缀零个数(b<=1e12) 题解 a ...

  5. hdu 1856 求集合里元素的个数 输出最大的个数是多少

    求集合里元素的个数 输出最大的个数是多少 Sample Input41 23 45 61 641 23 45 67 8 Sample Output42 # include <iostream&g ...

  6. 牛客小白月赛5-D-阶乘(求n内每个数的阶乘相乘后尾数为0的个数)

    题目描述 输入描述: 输入数据共一行,一个正整数n,意义如“问题描述”. 输出描述: 输出一行描述答案:一个正整数k,表示S的末尾有k个0 输入例子: 10 输出例子: 7 --> 示例1 输入 ...

  7. [LeetCode] Count Complete Tree Nodes 求完全二叉树的节点个数

    Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from W ...

  8. Soldier and Number Game---cf546D(打表求n的素因子个数)

    题目链接:http://codeforces.com/problemset/problem/546/D 题意: 给出一个n,n开始是a!/b!,每次用一个x去整除n得到新的n,最后当n变成1的时候经过 ...

  9. ACM数论-欧几里得与拓展欧几里得

    ACM数论——欧几里得与拓展欧几里得 欧几里得算法: 欧几里德算法又称辗转相除法,用于计算两个整数a,b的最大公约数. 基本算法:设a=qb+r,其中a,b,q,r都是整数,则gcd(a,b)=gcd ...

随机推荐

  1. (判断)window.open()窗口被关闭后执行事件

    $(function() { // start ready var $article_share=$('#body .article').find('li.share'); // $article_s ...

  2. python 命令行参数获取

    import argparse parser = argparse.ArgumentParser(description='Real-Time Filtering evaluation script ...

  3. Python 迭代对象、迭代器、生成器

    原文出处: liuzhijun 本文源自RQ作者的一篇博文,原文是Iterables vs. Iterators vs. Generators,俺写的这篇文章是按照自己的理解做的参考翻译,算不上是原文 ...

  4. mybatis 高级映射 简单例子

    1.建表 DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `gender` ) NOT NULL, `name` ) NOT NULL, `id` ...

  5. mac下搭建appium记录

    要安装的东西: jdk(要配置环境) , sdk(要配置环境) ,node(要配置环境), python(要配置环境) ,appium(要配置环境),appium-python-client ,xco ...

  6. 设置修改CentOS系统时间和时区

    1.yum install ntp,安装时间服务ntpdate time-a.nist.gov && hwclock -w (跟网络同步时间,并且写入主板BIos) 2.chkconf ...

  7. icape3 的使用

    在FPGA中,有时需要使用用户代码重配置FPGA,配置的内容可以是flash或者是其他的来源这样FPGA的启动模式有关,在本实验中配置文件是存放在flash中.实际的操作步骤如下: 1:生成一个工程, ...

  8. 客户端调用wcf服务,如何提高调用性能

    IO调用服务 1.使用using(每次自动释放) ; i < ; i++) { var watch = new Stopwatch(); watch.Start(); using (var cl ...

  9. upstream prematurely closed connection while reading response header from upstream

    upstream prematurely closed connection while reading response header from upstream nginx配置uwsgi的时候  ...

  10. windows解压缩版MySQL5.6.40的安装

    windows解压缩版MySQL5.6.40的安装 安装步骤: 1.下载mysql-5.6.40-winx64.zip https://cdn.mysql.com//Downloads/MySQL-5 ...