Light oj 1138 - Trailing Zeroes (III) (二分)
题目链接: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) (二分)的更多相关文章
- 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 ...
- light oj 1138 - Trailing Zeroes (III)【规律&&二分】
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- Light oj 1138 - Trailing Zeroes (III) 【二分查找 && N!中末尾连续0的个数】
1138 - Trailing Zeroes (III) problem=1138"> problem=1138&language=english&type=pdf&q ...
- 1138 - Trailing Zeroes (III) 二分
1138 - Trailing Zeroes (III) You task is to find minimal natural number N, so that N! contains exa ...
- LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)
http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS M ...
- LightOj 1138 - Trailing Zeroes (III) 阶乘末尾0的个数 & 二分
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题意:给你一个数n,然后找个一个最小的数x,使得x!的末尾有n个0:如果没有输出 ...
- lightoj 1138 - Trailing Zeroes (III)【二分】
题目链接:http://lightoj.com/volume_showproblem.php? problem=1138 题意:问 N. 末尾 0 的个数为 Q 个的数是什么? 解法:二分枚举N,由于 ...
- LightOJ 1138 Trailing Zeroes (III) 打表
就是统计5,然后当时因为发现最多有8000w个5的倍数,然后8000w/100,是80w,打表,二分找 然后我看网上的都是直接二分找,真是厉害 #include <cstdio> #inc ...
- LightOj 1138 Trailing Zeroes (III)
题目描述: 假设有一个数n,它的阶乘末尾有Q个零,现在给出Q,问n最小为多少? 解题思路: 由于数字末尾的零等于min(因子2的个数,因子5的个数),又因为2<5,那么假设有一无限大的数n,n= ...
随机推荐
- 解析Android开发优化之:从代码角度进行优化的技巧
下面我们就从几个方面来了解Android开发过程中的代码优化,需要的朋友参考下 通常我们写程序,都是在项目计划的压力下完成的,此时完成的代码可以完成具体业务逻辑,但是性能不一定是最优化的.一般来说 ...
- 安卓学习之--如何关闭所有的activity
根据Activity的声明周期 方法1 我们知道Android的窗口类提供了历史栈,我们可以通过stack的原理来巧妙的实现,这里我们在A窗口打开B窗口时在Intent中直接加入标志 Intent ...
- js风格技巧
1.一个页面的所有js都可以写成这样,比如: var index ={}; index.User = ****; index.Init = function(){ $("$tes ...
- sql字符串函数(转)
计算字符串长度 len()用来计算字符串的长度 select sname ,len(sname) from student 字符串转换为大.小写 lower() 用来将一个字符串转换为小写,upper ...
- 修改placeholder属性
input::-webkit-input-placeholder{ font-size:12px;}input:-ms-input-placeholder{ font-size:12px;}input ...
- Live555中RTP包的打包与发送过程分析
这里主要分析一下,live555中关于RTP打包发送的部分.在处理完PLAY命令之后,就开始发送RTP数据包了(其实在发送PLAY命令的response包之前,就会发送一个RTP包,这里传输就已经开始 ...
- BOM浏览器对象模型和API速查
什么是BOMBOM是Browser Object Model的缩写,简称浏览器对象模型BOM提供了独立于内容而与浏览器窗口进行交互的对象由于BOM主要用于管理窗口与窗口之间的通讯,因此其核心对象是wi ...
- Android手动画柱状图的例子
效果图如上,网上看到的例子,谨以此文记录一下,以后用到的地方再来翻翻. 核心技术是用Canvas和Paint画长方形. 源码地址:http://download.csdn.net/detail/abc ...
- Android自定义的webView——可实现的网页文本的复制
package com.example.customlinearlayout.view; import android.app.ProgressDialog; import android.conte ...
- Blog CSS
你好 print("你好.") haode