lightoj 1138 - Trailing Zeroes (III)【二分】
题目链接:http://lightoj.com/volume_showproblem.php?
problem=1138
题意:问 N。 末尾 0 的个数为 Q 个的数是什么?
解法:二分枚举N,由于0是由5×2 出现的,2的个数比5多故计算5的个数就可以。
代码:
#include <stdio.h>
#include <ctime>
#include <math.h>
#include <limits.h>
#include <complex>
#include <string>
#include <functional>
#include <iterator>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <ctime>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
using namespace std;
long long count_num(long long n)
{
long long num = 0;
while (n)
{
num += n / 5;
n /= 5;
}
return num;
}
int main()
{
int t;
scanf("%d",&t);
int cases = 1;
while (t--)
{
int n;
scanf("%d",&n);
printf("Case %d: ",cases++);
long long left = 1;
long long right = 1000000000000;
long long mid;
while (left <= right)
{
mid = (right + left) / 2;
long long tmp = count_num(mid);
if (tmp >= n)
right = mid - 1;
else
left = mid + 1;
}
if (count_num(left) != n)
puts("impossible");
else
printf("%lld\n",left);
}
return 0;
}
lightoj 1138 - Trailing Zeroes (III)【二分】的更多相关文章
- LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)
http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS M ...
- 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) 阶乘末尾0的个数 & 二分
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题意:给你一个数n,然后找个一个最小的数x,使得x!的末尾有n个0:如果没有输出 ...
- Light oj 1138 - Trailing Zeroes (III) (二分)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的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= ...
- 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 ...
随机推荐
- _vimrc配置
set nocompatible set encoding=utf8 set guioptions-=T set number set guifont=consolas:h12 source $VIM ...
- layer层次
Core Animation的基本使用(十六) 发表于2013/08/25由juluren layer tree addSublayer: 将层追加到接受者的子层数组中. insertSublayer ...
- 约束RMQ
不知道为什么网上找不到太多相关的资料,所以写一个小总结,并附有能用的代码,抛砖引玉. 约束RMQ,就是RMQ区间必须满足两项之差最大为1,采用ST表的话,这时候有O(n)建表,O(1)查询的优秀复杂度 ...
- MySQL redo log 与 binlog 的区别
MySQL redo log 与 binlog 的区别 什么是redo log 什么是binlog redo log与binlog的区别 1. 什么是redo log? redo log又称重做日志文 ...
- CSS3---圆角设置
1.border-radius是向元素添加圆角边框.border-radius:10px; /* 所有角都使用半径为10px的圆角 */ border-radius: 5px 4px 3px ...
- day15-python之变量和递归
1.局部变量与全局变量 #!/usr/bin/env python # -*- coding:utf-8 -*- # name='lhf' # def change_name(): # global ...
- Saving James Bond - Easy Version 原创 2017年11月23日 13:07:33
06-图2 Saving James Bond - Easy Version(25 分) This time let us consider the situation in the movie &q ...
- mongodb 的创建和使用
1. sudo apt-get install mongodb 2. 登陆数据库: mongo, 3. 创建数据库:use dbname 4. 插入数据: db.dbname.insert({&quo ...
- bzoj1708 [Usaco2007 Oct]Money奶牛的硬币 背包dp
[Usaco2007 Oct]Money奶牛的硬币 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 852 Solved: 575[Submit][Sta ...
- hdu1588:Gauss Fibonacci
对每个0<=i<n求f(g(i))的和,其中f(x)为斐波那契数列第x项,g(i)=k*i+b,k,b,n给定,模数给定. 斐波那契数有一种用矩阵乘法求的方法,这个矩阵A自己写,令F[i] ...