1138-trailing Zeroes (III)
|
PDF (中文版) |
Statistics |
Forum |
| Time Limit:2 second (s) |
Memory limit:32 MB |
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 |
Output for Sample Input |
3 1 2 5 |
Case 1:5 Case 2:10 Case 3:impossible |
Test instructions: give you a number q, which means n! The number of consecutive 0 in the end. Let you find the smallest n.
Ask N! Nakao number of consecutive 0:
ll change (ll x) { ll ans = 0; while (x) { ans + = X/5; x/= 5; } return ans;}
AC Code
#include <stdio.h> #include <string.h> #include <queue> #include <algorithm> #define INF 0x3f3f3f3f#define ll Long LONGLL Change (ll x) { ll ans = 0; while (x) { ans + = X/5; x/= 5; } return ans;} int main () { int T, n; int k = 1; scanf ("%d", &t); while (t--) { scanf ("%d", &n); LL L = 0, r = 100000000 * 5 +; LL mid, ans; while (R > L) { mid = (L + r)/2; if (change (mid) >= N) { ans = mid; R = Mid; } else L = mid + 1; } printf ("Case%d:", k++); if (change (ans) = = N) printf ("%lld\n", ans); else printf ("impossible\n"); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Light OJ 1138-trailing zeroes (III) "Two-point search && N! The number of consecutive 0 in the end of "