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

题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N。

我们可以知道N!里5(包括5的倍数)的个数比2(包括2的倍数)的个数多,所以1对应5!,2对应10!... 而末尾0的个数与N成正比,1e8对应的N最大是400000015。我用二分查询N对应末尾0的个数,要是计算出来末尾0的个数比给你的数还大就L=mid+1,否则就R=mid。

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; int get(int n) {
int cont = ;
while(n / ) {
cont += n / ;
n /= ;
}
return cont;
} int main()
{
int t , n;
scanf("%d" , &t);
for(int ca = ; ca <= t ; ca++) {
scanf("%d" , &n);
int L = , R = ;
while(L < R) {
int mid = (L + R) / ;
if(n <= get(mid))  
R = mid;
else
L = mid + ;
}
printf("Case %d: " , ca);
if(get(L) == n) {
printf("%d\n" , L);
}
else {
printf("impossible\n");
}
}
}

Light oj 1138 - Trailing Zeroes (III) (二分)的更多相关文章

  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)【规律&&二分】

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

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

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

  4. 1138 - Trailing Zeroes (III) 二分

    1138 - Trailing Zeroes (III)   You task is to find minimal natural number N, so that N! contains exa ...

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

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

  6. LightOj 1138 - Trailing Zeroes (III) 阶乘末尾0的个数 & 二分

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

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

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

  8. LightOJ 1138 Trailing Zeroes (III) 打表

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

  9. LightOj 1138 Trailing Zeroes (III)

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

随机推荐

  1. hdu 4972 A simple dynamic programming problem (转化 乱搞 思维题) 2014多校10

    题目链接 题意:给定一个数组记录两队之间分差,只记分差,不记谁高谁低,问最终有多少种比分的可能性 分析: 类似cf的题目,比赛的时候都没想出来,简直笨到极点..... 最后的差确定,只需要计算和的种类 ...

  2. 大流量IIS负载均衡NLB解决方案

    说白了就是  用多台WEB服务器   同时处理大量的http请求! 机器越多力量越大呵呵!!! 在现行的许多网络应用中,有时一台服务器往往不能满足客户端的要求,此时只能通过增加服务器来解决问题. 那么 ...

  3. EasyUi datagrid 单选框选中事件

    Easyui datagrid中的单选框默认是这样定义的 columns: [[ { field: 'CK', title: '', checkbox: true, width: 30 }]]. 平常 ...

  4. UVa 12096 The SetStack Computer【STL】

    题意:给出一个空的栈,支持集合的操作,求每次操作后,栈顶集合的元素个数 从紫书给的例子 A={{},{{}}} B={{},{{{}}}} A是栈顶元素,A是一个集合,同时作为一个集合的A,它自身里面 ...

  5. vssettings 的备份和导入

    vssettings 的作用:   vssettings的导出(也就是相当于是保存):   现在我们试试导入:找一个别人导出的包,我们导入试试.

  6. linux面试题3

    1. 下面的网络协议中,面向连接的的协议是: A . A 传输控制协议 B 用户数据报协议 C 网际协议 D 网际控制报文协议 2. 在/etc/fstab文件中指定的文件系统加载参数中, D 参数一 ...

  7. 鼠标悬停css3动画效果

    下载Demo 效果预览 html: <!DOCTYPE html> <html lang="en"> <head> <meta chars ...

  8. javascript一些有用但又不常用的特性

    1.onclick="save();return false;" 取消“浏览器默认行为”.     比如一个链接     <a href="http://zhida ...

  9. java 中的Exception RuntimeException 区别

    在java的异常类体系中: 1.Error和RuntimeException是非检查型异常,其他的都是检查型异常; 2.所有方法都可以在不声明throws的情况下抛出RuntimeException及 ...

  10. 《C++ primer》--第9章

    习题9.2 创建和初始化一个vector对象有4种方式,为每种方式提供一个例子. 解答: 分配指定数目的元素,并对这些元素进行值初始化: vector<int> ivec(10);     ...