http://lightoj.com/volume_showproblem.php?problem=1138

Trailing Zeroes (III)

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使N!中0的个数等于q

0是有5乘4、2、8等等构成的,N中只要有因子5,那么N!中一定能构成0,所以我们只需要找N中因子5的个数,然后用二分来快速查找N

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm> using namespace std;
typedef long long ll; ll solve(ll n)
{
ll ans = ;
while(n)
{
ans += n / ;
n /= ;
}
return ans;
}//求n中因子5的个数 int main()
{
int t, p = ;
ll q;
scanf("%d", &t);
while(t--)
{
p++;
scanf("%lld", &q);
ll low = , high = ;
while(low <= high)
{
ll mid = (low + high) / ;
ll m = solve(mid);
if(m < q)
low = mid + ;
else
high = mid - ;
}//二分
if(solve(low) == q)
printf("Case %d: %lld\n", p, low);
else
printf("Case %d: impossible\n", p);
}
return ;
}

LightOJ 1138 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. LightOj 1138 - Trailing Zeroes (III) 阶乘末尾0的个数 & 二分

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

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

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

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

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

  5. LightOJ 1138 Trailing Zeroes (III) 打表

    就是统计5,然后当时因为发现最多有8000w个5的倍数,然后8000w/100,是80w,打表,二分找 然后我看网上的都是直接二分找,真是厉害 #include <cstdio> #inc ...

  6. LightOj 1138 Trailing Zeroes (III)

    题目描述: 假设有一个数n,它的阶乘末尾有Q个零,现在给出Q,问n最小为多少? 解题思路: 由于数字末尾的零等于min(因子2的个数,因子5的个数),又因为2<5,那么假设有一无限大的数n,n= ...

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

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

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

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

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

随机推荐

  1. django-DIL模板自定义过滤器,自定义标签,自定义包含标签

    自定义过滤器 DTL模板语言生来只是为了方便的展示信息,所以与编程语言相比显得有点薄弱,有时候不能满足我们的需求.因此django提供了一个接口,让开发者能自定义标签和过滤器. 首先,你需要添加一个t ...

  2. python 发送带附件的 邮件

    from email.MIMETextimportMIMETextfrom email.MIMEMultipartimportMIMEMultipartimport smtplib mail_host ...

  3. SSD

    https://blog.csdn.net/WZZ18191171661/article/details/79444217 论文题目:SSD: Single Shot MultiBox Detecto ...

  4. Spring Boot 集成servlet,发布为可直接运行的war包,方便后续打包为docker镜像。

    背景:Spring Boot 集成servlet,发布为可直接运行的war包,方便后续打包为docker镜像. 原文地址 https://github.com/weibaohui/springboot ...

  5. 和大于S的最小子数组 · Minimum Size Subarray Sum

    [抄题]: 给定一个由 n 个正整数组成的数组和一个正整数 s ,请找出该数组中满足其和 ≥ s 的最小长度子数组.如果无解,则返回 -1. 给定数组 [2,3,1,2,4,3] 和 s = 7, 子 ...

  6. 9-eclispe中右键BuildPath没有了

    Eclipse 右上角的代码视图,选择Java就好了!

  7. 可跨平台C++开源图形图像框架:openFrameworks

    博客参考:https://www.hahack.com/codes/openframeworks-intro/#%E4%BB%80%E4%B9%88%E6%98%AF-openframeworks 和 ...

  8. 利率计算v5.0--结对--软件工程

    利率计算v5.--测试--软件工程 1.任务结对同伴: 名字:王昕明 学号: 博客地址 :http://home.cnblogs.com/u/xinmingwang/ Git : https://gi ...

  9. <<高级计算机网络>>(Advaned Computer Networks) 徐恪 徐明伟 陈文龙 马东超

    目录 第1章 计算机网络与Internet1 1.1 引言1 1.2 Internet发展历史2 1.2.1 互联网发展的主要阶段4 1.2.2 互联网在中国的发展5 1.2.3 互联网主要创新5 1 ...

  10. cucumber安装步骤

    #Start Guide##Environment###1. Install Ruby Verify your installation by running ruby -v in a termina ...