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 ...
随机推荐
- 记一次Linux系统被入侵的过程
记一次Linux系统被入侵的过程 1. 前期现象 前期现象,宋组那边反应开发环境192.161.14.98这台机器通过公网下载文件,很慢,ping百度丢包严重.因为这台机器是通过楼下adsl拨号上网, ...
- 28. TRIGGERS ,29. USER_PRIVILEGES,30. VIEWS
28. TRIGGERS TRIGGERS表提供有关触发器的信息.要查看有关表的触发器的信息,您必须具有该表的TRIGGER权限. TRIGGERS表有以下列: TRIGGER_CATALOG :触发 ...
- Linux文件属性和压缩解压
目 录 第1章 Linux系统文件的属性 1 1.1 命令ls 1 1.2 inode 2 1.3 文件属性 2 1.4 env命令 2 1.5 注意: 2 第2章 ...
- Java自动生成asmx的webservice代码
第一种方式:针对CXF自动生成的代码对响应类大小写区别问题,可以使用此方法. 工具为Eclipse. 新建Web Service Client. 输入地址点击finish即可自动生成. 调用方式: p ...
- Mybatis判断int类型是否为空
Mybatis判断int是否为空只要!=null就行了
- php 复制文件夹
public function recurse_copy($src,$des) { $dir = opendir($src); @mkdir($des); while(false !== ( $fil ...
- .NET中的缓存实现
软件开发中最常用的模式之一是缓存,这是一个简单但非常有效的概念,想法是重用操作结果,执行繁重的操作时,我们会将结果保存在缓存容器中,下次我们需要该结果时,我们将从缓存容器中取出它,而不是再次执行繁重的 ...
- Python 和 Flask实现RESTful services
使用Flask建立web services超级简单. 当然,也有很多Flask extensions可以帮助建立RESTful services,但是这个例实在太简单了,不需要使用任何扩展. 这个we ...
- [POJ1984]Navigation Nightmare
[POJ1984]Navigation Nightmare 试题描述 Farmer John's pastoral neighborhood has N farms (2 <= N <= ...
- Cloud BOS平台-自定义用户联系对象
适用业务场景:新增用户时,联系对象类型默认为:职员.客户.供应商.客户需要增加一类"承运商",类型选择"承运商"时,联系对象只显示相应的承运商."承运 ...