- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define M 1000003
- #define S 1000003
- #define LL long long
- using namespace std;
- int n;
- int BS(int h, int l){
- int p, q, m, f = 0;
- while(h >= l){
- p = h+l;
- if(p&1)p += 5;
- m = p/2;
- q = m;
- if(f == m)return -1;
- f = m;
- int ans = 0;
- while(q > 0){
- ans += q/5;
- q /= 5;
- }
- if(ans == n)return m;
- else if(ans > n)h = m;
- else l = m;
- }
- return -1;
- }
- int main(){
- int t, cs = 0;
- scanf("%d", &t);
- while(t--){
- scanf("%d", &n);
- int high = 5*n;
- int low = 5;
- int a = BS(high, low);
- printf("Case %d: ", ++cs);
- printf((a < 0)?"impossible\n":"%d\n", a);
- }
- return 0;
- }
Friday, March 11, 2016
LightOJ - 1138 - Trailing Zeroes (III)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment