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
代码:
#include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<queue> #include<stack> #include<algorithm> using namespace std; #define N 0x3f3f3f3f int Num0(int n) { int sum = 0; while(n) { sum += n/5; n /= 5; } return sum; } void Search(int w) ///二分搜索 { int L=0, R=N, mid; while(L<=R) { mid = (L+R)>>1; if(w <= Num0(mid)) R = mid - 1; else L = mid + 1; } if(Num0(L)==w) printf("%d\n", L); else printf("impossible\n"); } int main() { int iCase=1, n, t; scanf("%d", &t); while( t-- ) { scanf("%d", &n); printf("Case %d: ", iCase++); Search(n); } return 0; }
勿忘初心
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步