Link
Description
You task was 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! = 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
Code:
#include <cstdio>#include<cstring>#include<cstdlib>#include<iostream>#include<queue>#include<stack>#include<algorithm>using namespacestd;#defineN 0x3f3f3f3fintNUM0 (intN) { intsum =0; while(n) {sum+ = n/5; N/=5; } returnsum;}voidSearch (intW///Two-point search{ intL=0, r=N, Mid; while(l<=R) {Mid= (l+r) >>1; if(W <=NUM0 (mid)) R= Mid-1; ElseL= Mid +1; } if(NUM0 (L) = =W) printf ("%d\n", L); Elseprintf ("impossible\n");}intMain () {intIcase=1, N, t; scanf ("%d", &t); while(t--) {scanf ("%d", &N); printf ("Case %d:", icase++); Search (n); } return 0;}
(binary search number theory) (factorial of 0 numbers in factorial) light OJ--1138