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 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e5+,M=4e6+,inf=1e9+;
int a[]={,,,,,,,,,,,,};
int check(int x)
{
int sum=;
for(int i=;i<;i++)
sum+=x/a[i];
return sum;
}
int main()
{
int x,y,z,i,t;
int T,cas=;
scanf("%d",&T);
while(T--)
{
scanf("%d",&x);
int st=;
int en=;
while(st<en)
{
int mid=(st+en)>>;
if(check(mid)>=x)
en=mid;
else
st=mid+;
}
printf("Case %d: ",cas++);
if(check(st)==x)
printf("%d\n",st);
else
printf("impossible\n");
}
return ;
}
LightOJ 1138 二分的更多相关文章
- LightOJ - 1138 (二分+阶乘分解)
题意:求阶乘尾部有Q(1 ≤ Q ≤ 108)个0的最小N 分析:如果给出N,然后求N!尾部0的个数的话,直接对N除5分解即可(因为尾部0肯定是由5*2构成,那么而在阶乘种,2的因子个数要比5少,所以 ...
- 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! ...
- 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,由于 ...
- 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 不找规律-理智推断-二分
其实有几个尾零代表10的几次方但是10=2*510^n=2^n*5^n2增长的远比5快,所以只用考虑N!中有几个5就行了 代码看别人的: https://blog.csdn.net/qq_422797 ...
- 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= ...
随机推荐
- 解决ubuntukylin 13.10安装wine时无法解决软件包依赖问题
在ubuntukylin 13.10中,无论是在软件中心安装wine还是通过apt-get install安装wine都会出现软件包依赖问题且无法解决. 问题重现 在软件中心安装wine报错例如以下: ...
- MVC架构模式(转载)
MVC架构模式 [概念理解] MVC模式和C++的实现 面向对象的设计模式是经验的总结,MVC思想是原先用于构建用户界面的.这篇文章主要论述了如何在新的Web应用领域中使用设计模式和MVC架构.文章首 ...
- SVN分支与主干
我的理解:在svn版本库中创建两个目录,一个主干如truck,一个分支目录如branch(注:分支可以创建多个),分别在客户端中检出代码,在分支中进行bug的修复以及新模块的开发,开发完后再merge ...
- 软件测试人员需要精通的开发语言(3)--- Linux
Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户.多任务.支持多线程和多CPU的操作系统.不得不说下,中国产的红旗系统,牛的一逼,造价很贵,但具体何用处估 ...
- Xshell连接不上行Linux系统
之前出现了.我的Linux系统上的主机可以ping通windows的一台电脑, windows也可以ping的通Linux.但是Xshell不能连接. 第一,我感觉是不是我Linux系统的端口被防火墙 ...
- CoreMotion 加速器陀螺仪
初始化CoreMotion #import <CoreMotion/CoreMotion.h> CMMotionManager *motionManager = [[CMMotionMan ...
- js滚动到指定位置显示或隐藏元素
$(function(){ $(window).scroll(function(){ var scroll_top=$(window).scrollTop(); console.log(scroll_ ...
- fkwの题目(祝松松生日快乐!)
麓山国际实验学校 傅少,匡哥和巨夫出的题目(共3道) 一.题目概况 题目名称 打地铺 泡妹子 开房间 题目类型 传统 传统 传统 可执行文件名 deeeep soccer room 输入文件名 dee ...
- G20峰会将会给数字货币带来哪些影响?
G20峰会对于全球经济有着举足轻重的影响,其成员人口占全球的2/3,国土面积占全球的60%,国内生产总值占全球的90%,贸易额占全球的75%……作为国际经济合作的主要平台,G20在引领和推动国际经济合 ...
- [转载]Java集合容器简介
Java集合容器主要有以下几类: 1,内置容器:数组 2,list容器:Vetor,Stack,ArrayList,LinkedList, CopyOnWriteArrayList(1.5),Attr ...