Trailing Zeroes (III)
| Time Limit: 2000MS |
|
Memory Limit: 32768KB |
|
64bit IO Format: %lld &%llu |
Submit Status
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
Source
Problem Setter:jane Alam Jan
Arithmetical!!! Add two points ....
1#include <stdio.h>2#include <string.h>3#include <stdlib.h>4#include <math.h>5#include <iostream>6#include <algorithm>7#include <climits>8#include <queue>9 #definell Long LongTen One A using namespacestd; - ll ans; - ll Zero (ll num) the { -ll i,sum =0; - for(i =5; I <= num; I *=5) -Sum + = num/i; + returnsum; - } + voidCheckintN) A { atll low =5, Mid,high; -High =0x3f3f3f3f3f; - while(Low <=High ) - { -Mid = (Low+high)/2; -ll temp =Zero (mid); in if(N <temp) -High = mid-1; to Else if(N >temp) +Low = mid+1; - Else if(n = =temp) the { * if(Mid = =Low ) $ {Panax NotoginsengAns =mid; - return; the } +High =mid; A } the } + } - $ intMainvoid) $ { - intt,n,cnt =1; -Cin>>T; the while(t--) - {Wuyiscanf"%d",&n); theAns =-1; - check (n); Wu if(ans = =-1) -printf"Case %d:impossible\n", cnt++); About Else $printf"Case %d:%lld\n", cnt++, ans); - } - return 0; -}
Light OJ 1138