题目链接:http://lightoj.com/volume_showproblem.php?problem=1138

题意:给你一个数n,然后找个一个最小的数x,使得x!的末尾有n个0;如果没有输出impossible

可以用二分求结果,重点是求一个数的阶乘中末尾含有0的个数,一定和因子5和2的个数有关,因子为2的明显比5多,所以我们只需要求一个数的阶乘的因子中一共有多少个5即可;

LL Find(LL x)
{
LL ans = ;
while(x)
{
ans += x/;
x /= ;
}
return ans;
}

例如125! 125/5 = 25;所以125!中含5的项为25*5+24*5+23*5+...+3*5+2*5+1*5 = 25!*5 

所以125!末尾有25+5+1 = 31 个0;

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
typedef long long LL;
#define N 1000001
using namespace std;
const double eps = 1e-; LL Find(LL x)
{
LL ans = ;
while(x)
{
ans += x/;
x /= ;
}
return ans;
} int main()
{
int T, t = , n;
scanf("%d", &T);
while(T --)
{
scanf("%d", &n);
LL ans = , L = , R = ;
while(L <= R)
{
LL Mid = (L+R)/;
LL ret = Find(Mid); if(ret == n)
ans = Mid;
if(ret >= n)
R = Mid - ;
else
L = Mid + ;
}
if(ans == )
printf("Case %d: impossible\n", t++);
else
printf("Case %d: %lld\n", t++, ans);
}
return ;
}

LightOj 1138 - Trailing Zeroes (III) 阶乘末尾0的个数 & 二分的更多相关文章

  1. LightOj 1090 - Trailing Zeroes (II)---求末尾0的个数

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1090 题意:给你四个数 n, r, p, q 求C(n, r) * p^q的结果中末尾 ...

  2. LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)

    http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS     M ...

  3. [LeetCode] Factorial Trailing Zeroes 求阶乘末尾零的个数

    Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...

  4. [LeetCode] 172. Factorial Trailing Zeroes 求阶乘末尾零的个数

    Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explan ...

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

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

  6. LightOj 1138 Trailing Zeroes (III)

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

  7. 172. Factorial Trailing Zeroes(阶乘中0的个数 数学题)

    Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explan ...

  8. LightOJ 1138 Trailing Zeroes (III) 打表

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

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

随机推荐

  1. Android MVVM框架RoboBinding初探

    RoboBinding是一个实现了数据绑定 Presentation Model(MVVM) 模式的Android开源框架.MVVM模式是MVC模式的重要更新,使得项目结构更加的优美,易于维护以及方便 ...

  2. (转)Linq学习笔记

    写在前面 最近在看Linq,在博客园看到这篇文章,写的通俗易懂,转来和大家一起做个分享.原文地址http://www.cnblogs.com/goscan/archive/2011/05/05/Lin ...

  3. COJ574 数字序列

    试题描述   霸中智力测试机构的一项工作就是按照一定的规则删除一个序列的数字,得到一个确定的数列.陈思同学很渴望成为霸中智力测试机构的主管,但是他在这个工作上做的并不好,俗话说熟能生巧,他打算做很多练 ...

  4. Graph database_neo4j 底层存储结构分析(3)

    3.3  通用的Store 类型 3.3.1    id 类型 下面是 neo4j db 中,每种Store都有自己的ID文件(即后缀.id 文件),它们的格式都是一样的. [test00]$ls - ...

  5. AspNetPager常用属性及一些样式(本文摘自网络,作者:x123jing)

    AlwaysShow 总是显示分页控件,即使要分页的数据只有一页 AlwaysShowFirsLastPageNumbr 是否总是显示第一页和最后一页数字页索引按钮 BackImageUrl 面板的背 ...

  6. java+easyui实例

    1.首先引入easyui包 在jsp页面上引用以下文件: <link rel="stylesheet" type="text/css" href=&quo ...

  7. 【C语言】11-指针

    直接引用 1. 回想一下,之前我们是如何更改某个变量的值? 我们之前是通过变量名来直接引用变量,然后进行赋值: char a; a = 10;   2. 看上去是很简单,其实程序内部是怎么操作的呢? ...

  8. grep 命令搜索 带空格的字符

    grep - n ' a[[:space:]]b' 就能搜索到 'a    b'类似的字符了 如果要搜索带单引号的 用双引号括起来 如果要搜索带双引号的 用单引号括起来

  9. string.h文件中函数用法

    下面为string.h文件中函数的详细用法: strcpy函数名:strcpy功 能: 拷贝一个字符串到另一个用 法: char *strcpy(char *destin, char *source) ...

  10. 在Eclipse中配置Tomcat 创建和运行Servlet/JSP

    在Eclipse中配置Tomcat 创建和运行Servlet/JSP 步骤一:在Eclipse中配置Tomcat(注意下载Eclipse IDE for Java EE Developers) (1) ...