Trailing Zeroes (III) LightOJ - 1138 二分+找规律
Time Limit: 2 second(s) | Memory Limit: 32 MB |
You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in decimal notation. As you know N! = 1*2*...*N. For example, 5! = 120, 120 contains one zero on the trail.
Input
Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case contains an integer Q (1 ≤ Q ≤ 108) in a line.
Output
For each case, print the case number and N. If no solution is found then print 'impossible'.
Sample Input |
Output for Sample Input |
3 1 2 5 |
Case 1: 5 Case 2: 10 Case 3: impossible |
题意:求出现一个最小的数的阶乘满足末尾有连续q个0。
思路:一个最小的数末尾要出现0一定要是能被5或10整除的,0的连续长度与数组大小正相关,故二分数字得解。
- #include<set>
- #include<map>
- #include<stack>
- #include<cmath>
- #include<queue>
- #include<cstdio>
- #include<string>
- #include<cstring>
- #include<iostream>
- #include<limits.h>
- #include<algorithm>
- #define mem(a,b) memset(a,b,sizeof(a))
- using namespace std;
- const int INF=1e9;
- typedef unsigned long long ll;
- typedef long long LL;
- int main()
- {
- int T,cases=;
- scanf("%d",&T);
- while(T--)
- {
- int q;
- LL ans=-;
- scanf("%d",&q);
- int l=,r=q*,mid;//为什么右端点是q*5,因为q*5>=ans.想一想为什么(hint:刚才那个序列。。。)
- while(l<=r)
- {
- mid=(l+r)/;
- int m=mid,wu=,count=;
- while(m>=wu)
- {
- int p=m;
- p/=wu;
- count+=p;
- wu*=;
- }
- if(count==q)
- {
- ans=mid;
- break;
- }
- else if(count>q)
- r=mid-;
- else
- l=mid+;
- }
- if(ans==-)
- printf("Case %d: impossible\n",cases++);
- else
- printf("Case %d: %lld\n",cases++,ans/*);
- }
- }
代码转自(https://blog.csdn.net/duan_1998/article/details/72566106)
Trailing Zeroes (III) LightOJ - 1138 二分+找规律的更多相关文章
- Trailing Zeroes (III) LightOJ - 1138 不找规律-理智推断-二分
其实有几个尾零代表10的几次方但是10=2*510^n=2^n*5^n2增长的远比5快,所以只用考虑N!中有几个5就行了 代码看别人的: https://blog.csdn.net/qq_422797 ...
- Trailing Zeroes (III) LightOJ - 1138(二分)
You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in d ...
- Trailing Zeroes (III)(lightoj 二分好题)
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 ...
- LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)
http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS M ...
- light oj 1138 - Trailing Zeroes (III)【规律&&二分】
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- LightOJ Trailing Zeroes (III) 1138【二分搜索+阶乘分解】
1138 - Trailing Zeroes (III) PDF (English) problem=1138" style="color:rgb(79,107,114)" ...
- 1138 - Trailing Zeroes (III) 二分
1138 - Trailing Zeroes (III) You task is to find minimal natural number N, so that N! contains exa ...
- 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 ...
随机推荐
- [原]排错实战——使用process explorer替换任务管理器
原Aha总结注册表process explorersysinternalsprocess monitor 前言 一般,我们会使用任务管理器查看系统中有哪些进程正在运行,强制杀掉某个进程.可是系统自带的 ...
- Java之线程通信的应用:经典例题:生产者/消费者问题
/** * 线程通信的应用:经典例题:生产者/消费者问题 * * 生产者(Productor)将产品交给店员(Clerk),而消费者(Customer)从店员处取走产品, * 店员一次只能持有固定数量 ...
- 通过OAuth2.0 获取授权访问SF 用户数据
站长资讯: 创建应用程序 新建应用程序 访问示例(Python+django) 环境准备: index.html 两种方式: 方式一:采用由用户授权,调用者无需知道SF的用户名与密码 方式二:直接 ...
- [TJOI2017]不勤劳的图书管理员(分块+树状数组)
有一个数组开大会MLE开小会RE的做法:就是树套树,即树状数组套主席树,这种方法比较暴力,然而很遗憾它不能通过,因为其时空复杂度均为O(nlog2n). 想到一种不怎么耗内存,以时间换空间,分块!单次 ...
- shell_xtrabackup_backup_mysql
#!/bin/bash# Name: xtra_back_mysql.sh# Desc:该脚本使用xtrabackup工具对mysql数据库进行增量备份,根据自己需求可以自行修改# Usage:./x ...
- 迅为IMX6Q开发板提供原理图_底板PCB_驱动程序源码_芯片和LCD数据手册_开发板环境_使用手册
迅为IMX6开发板: Android4.4/6.0系统 Linux + Qt5.7系统 Ubuntu12.04系统 部分案例:HMI:3D打印机:医疗设备:工控机:触控一体机:车载终端 核心板 ...
- 基础篇十:模块介绍(--with-help_random_index_module)
配置语法: 下面开始配置: cd /etc/nginx/conf.d/default.conf
- 52)PHP,加了单例模式的数据库代码
<?php class db { public $host ;//= "localhost";//定义默认连接方式 public $User;//= "root&q ...
- 48)PHP,工厂模式
为啥需要工厂模式啊: (原来是生产类的工具——————————) 工厂类的代码格式: <?php class factory{ //Instance表示“实例”,“对象” static func ...
- java作业-----方法重载
满足方法重载的条件:1.方法名相同 2.参数类型不同,参数个数不同,参数类型的顺序不同. 同时,方法的返回值不作为方法重载的判断条件.