- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long unsigned
- ll zero(ll n){
- ll dev = 5;
- ll c = 0;
- while(n>= dev){
- c+= (n)/dev;
- dev*=5;
- }
- return c;
- }
- void bisec(ll n){
- ll start = 0, end = 800000000, now, mid;
- bool flag = false;
- //cout<<"comes";
- while(start<=end){
- mid = (start+end)/2;
- now = zero(mid);
- //cout<<"start mid end now = "<<start<<" "<<mid<<" "<<end<<" "<<now<<endl;
- if(now>n){
- end = mid-1;
- }
- else if(now<n) start = mid+1;
- else {flag = true;end = end-1;}
- }
- if(flag){printf("%llu\n", mid);return;}
- else{printf("impossible\n");return;}
- /*
- if(zero(now) == n) {printf("%llu\n", now);return;}
- for(ll p = start; p <= end; p++){
- if(zero(p)<n) continue;
- if(zero(p) == n) {printf("%llu\n", p);break;}
- else {printf("impossible\n");break;}
- }
- return;
- */
- }
- int main(){
- int ts;
- cin>>ts;
- for(int i = 1; i <=ts; i++){
- ll a;
- scanf("%llu", &a);
- printf("Case %d: ", i);
- bisec(a);
- }
- return 0;
- }
Friday, 28 July 2017
Lightoj 1138 - Trailing Zeroes (III)
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
-
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
No comments:
Post a Comment