题目链接: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. phonegap+html5开发app的一些总结

    1.Css3圆角白边:使用css3圆角效果时,在android某些机器上会产生白边,所以应该在圆角的div外套一个div(背景色和外部相同),然后有圆角效果的div 内部使用自己的背景色 border ...

  2. Windows环境下Redis

    Redis 是一个高性能的key-value数据库, 使用内存作为主存储,数据访问速度非常快,当然它也提供了两种机制支持数据持久化存储.比较遗憾的是,Redis项目不直接支持Windows,Windo ...

  3. MySQL 用户管理——权限表

    权限表 权限表存放在mysql数据库中 user表结构 用户列:Host.User.Password 权限列:*priv 资源控制列:max* 安全列:其余   db表 存储了用户对某个数据库的操作权 ...

  4. QDialog, QFileDialog 和 QDesktopServices 的使用方法

    Qt中的QDialog类是用来生成对话框的类,QFileDialog 类是QDialog的衍生类,主要用来生成打开文件,或是打开文件目录的对话框,或者是保存文件的对话框,下面我们一一来看代码: 1. ...

  5. [ZT] 酒店大洗脑:最全各大国际酒店集团族谱图

    原文地址: http://www.licai.com/yuedu/201411-62884.html 如果你对各大耳熟能详的国际酒店管理集团还有什么问题,相信今天和你分享的各大酒店集团家族系谱图和最全 ...

  6. 创建自定义 jQuery 移动主题

    自定义页面.工具栏.内容.表单元素.列表.按钮等元素的外观 智能电话和平板设备的高采用率最终导致增加了对移动 Web 开发人员和设计师的需求.jQuery Mobile 框架支持您创建能与原生应用程序 ...

  7. safedog的小技巧

    限制3389连接:下载SafedogServer\SafeDogGuardCenter\ProGuardData.ini回本地,然后本地搭建安全狗,覆盖,查看计算机名,修改自己计算机名再连接. 卸载安 ...

  8. 去掉网址中的 html编码

    修改 web\urlManager  createUrl函数,去掉 urlEncode函数

  9. windows下Ruby开发环境搭建

    一.下载 下载RubyInstaller 二.安装 按照提示安装 安装完毕后,在cmd命令窗口,输入:ruby -v 查询rbuy版本:输入gem -v 查询gem版本 三.Ruby插件(Redis插 ...

  10. ORA-12518: TNS: 监听程序无法分发客户机连接

    在团队成员增多时,经常出现“无法分发客户端连接”等问题.在网上搜索一番后,最终解决了该问题,现将解决方案总结如下,以供参考和以后备用. 原因:团队成员增多,原有数据库设置不够用,导致连接plsql和启 ...