首页 > 代码库 > LightOJ 1138 二分
LightOJ 1138 二分
1138 - Trailing Zeroes (III)
PDF (English) | Statistics | Forum |
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+10,M=4e6+10,inf=1e9+10;int a[20]={5,25,125,625,3125,15625,78125,390625,1953125,9765625,48828125,244140625,1220703125};int check(int x){ int sum=0; for(int i=0;i<13;i++) sum+=x/a[i]; return sum;}int main(){ int x,y,z,i,t; int T,cas=1; scanf("%d",&T); while(T--) { scanf("%d",&x); int st=0; int en=500000000; while(st<en) { int mid=(st+en)>>1; if(check(mid)>=x) en=mid; else st=mid+1; } printf("Case %d: ",cas++); if(check(st)==x) printf("%d\n",st); else printf("impossible\n"); } return 0;}
LightOJ 1138 二分
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。