diff --git a/Codes/1982 B - Collatz Conjecture/1982B.cpp b/Codes/1982 B - Collatz Conjecture/1982B.cpp index bad5cf9..0ee2ecb 100644 --- a/Codes/1982 B - Collatz Conjecture/1982B.cpp +++ b/Codes/1982 B - Collatz Conjecture/1982B.cpp @@ -26,19 +26,14 @@ void solve() { int x,y,k; cin>>x>>y>>k; - while(k) + while(k && x>1) { - int r=x%y; - x += min(k,y-r); - k -= min(k,y-r); + int r=y-x%y; + x += min(k,r); + k -= min(k,r); while(x%y==0) x /= y; - if(x==1) - { - cout<