light oj 1138
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Description
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
3
1
2
5
Sample Output
Case 1: 5
Case 2: 10
Case 3: impossible
题意:寻找最小的自然数N,使其阶乘的末尾有Q个0.
思路:只有2和5相乘时末尾才会出现0,在阶乘过程中,因子2的个数足够多,所以每遇到一个5,末尾就会出现一个0,因此问题转化为求1到N这N个整数中包含了多少个因子5。
#include<stdio.h>
#include<string.h>
#define MAX 0x3f3f3f
#define LL long long
LL fun(LL x)
{
LL ans=0;
while(x)
{
ans+=x/5;
x=x/5;
}
return ans;
}
int main()
{
int n,k=1;
LL m;
scanf("%d",&n);
while(n--)
{
scanf("%lld",&m);
LL left=0;
LL right=400000010;
LL mid;
while(left<=right)
{
mid=(left+right)>>1;
if(fun(mid)>=m)
right=mid-1;
else
left=mid+1;
}
printf("Case %d: ",k++);
if(fun(left)!=m)
printf("impossible\n");
else
printf("%lld\n",left);
}
return 0;
}
light oj 1138的更多相关文章
- Light oj 1138 - Trailing Zeroes (III) (二分)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N. 我们可以知 ...
- 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 ...
- 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
链接 Description You task is to find minimal natural number N, so that N! contains exactly Q zeroes on ...
- Light OJ 1114 Easily Readable 字典树
题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...
- Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖
题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...
- Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖
标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...
- Light OJ 1316 A Wedding Party 最短路+状态压缩DP
题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...
随机推荐
- [codility]Min-abs-sum
https://codility.com/demo/take-sample-test/delta2011/ 0-1背包问题的应用.我自己一开始没想出来.“首先对数组做处理,负数转换成对应正数,零去掉, ...
- linux和window下mkdir函数
通过WIN32宏进行判断 window下mkdir函数 #include<direct.h> int _mkdir( const char *dirname ); linux下 ...
- Silverlight之OOB模式下的一些事
本文简介: 1.为什么要使用OOB?使用OOB的作用? 2.如何实现OOB模式 3.对OOB进行一些设置: 4.检测OOB的安装状态: 5.更新应用程序: 6.WebBrowser控件: 7.桌面通知 ...
- 给枚举加上Description,必要时,可以直接获取枚举类型代表的中文
http://www.cnblogs.com/lyl6796910/p/3958768.html
- 武汉北大青鸟解读2016年10大IT热门岗位
武汉北大青鸟解读2016年10大IT热门岗位 2016年1月5日 13:37 北大青鸟 这是IT从业者的辉煌时代,IT行业的失业率正处在历史的低点,而且有的岗位——例如网络和安全工程师以及软件开发人员 ...
- bzoj2668
对于这种题很容易看出是费用流吧…… 但这道题不容易建模: 首先是怎么表示目标状态和其实状态,看起来有黑有白很复杂 但实际上,不难发现,白色格子没什么用,起决定作用的是黑格子 也就是我们可以把问题简化: ...
- 关闭 VS的实时调试器
可以这样关闭: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger HKEY_LOCAL_ ...
- mysqldump使用
mysqldump常用于MySQL数据库逻辑备份. 1.各种用法说明 A. 最简单的用法: mysqldump -uroot -pPassword [database name] > [dump ...
- Oracle Data Guard
DG 是 Oracle Data Guard 的简称.也就是Oracle11g的 数据卫士. 由于在工作中 Oracle和 SQL SERVER2008 同时都需要维护管理.给我的感觉这里的 DG 其 ...
- 【转】adb控台中Permission denied的解决方案
原文网址:http://blog.csdn.net/wkl305268748/article/details/13504171 [前提]手机一定要root 在控制台中想要将电脑上c盘中的tcpdump ...