lightoj1138Trailing Zeroes (III) 二分
来源:互联网 发布:国产电视推荐 知乎 编辑:程序博客网 时间:2024/06/03 20:16
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
Hint
题意
n尾部0的个数 找到这个n
题解:
AC代码
#include <cstdio>#include <iostream>#include <queue>#include <map>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;const int N = 5e5+5;int a[N];int l,n,m;/*求一个数阶乘尾部0的个数*/int check(LL k){ int ans = 0; while (k){ k/=5; ans+=k; } return ans;}int main(){ int t; scanf("%d",&t); int kase = 1; while (t--){ int q; scanf("%d",&q); printf("Case %d: ",kase++); //右边界好大!! LL l = 0,r = 1e9; while (l<=r){ LL mid = (l+r)>>1; if (check(mid)>=q) r = mid-1; else l = mid+1; } if (check(r+1)!=q) printf("impossible\n"); else printf("%lld\n",r+1); } return 0;}
阅读全文
0 0
- lightoj1138Trailing Zeroes (III) 二分
- lightoj1138Trailing Zeroes (III)
- Trailing Zeroes (III)<二分>
- *lightoj 1138 Trailing Zeroes (III) | 二分+数学
- LightOJ-1138 Trailing Zeroes (III) (二分搜索)
- lightoj 1138 - Trailing Zeroes (III)【二分】
- LightOJ-1138 Trailing Zeroes (III) (二分搜索)
- Lightoj 1138 Trailing Zeroes (III) 【二分】
- light oj 1138 - Trailing Zeroes (III)《《二分》》
- Light oj Trailing Zeroes (III) (二分查找)
- LightOJ 1138 Trailing Zeroes (III)(二分)
- LightOJ 1138 - Trailing Zeroes (III)【二分】
- LightOJ 1138Trailing Zeroes (III)(二分)
- LightOJ 1138 Trailing Zeroes (III) 二分查找
- LightOJ 1138 - Trailing Zeroes (III) 二分
- 【lightoj 1138】Trailing Zeroes (III) (二分)
- lightoj-1138-Trailing Zeroes (III) -二分查找
- LightOJ Trailing Zeroes (III) 1138【二分搜索+阶乘分解】
- 进程池和线程池
- Spark 之 RDD
- Weird Rounding
- POJ-2236-Wireless Network [并查集]
- [LeetCode]437. Path Sum III(求二叉树中路径和等于sum的数量)
- lightoj1138Trailing Zeroes (III) 二分
- 九个步骤让你成为PHP专家
- 今年暑假不AC
- 剑指offer-扑克牌顺子
- CSS文本与字体
- HDU 1599 find the mincost route (floyd)
- Fragment懒加载
- JAVA从网络下载文件到本地
- tomcat 优化操作