From ca14f7d824cd35f9bf608738fbad7616d57c9e6b Mon Sep 17 00:00:00 2001 From: ShazidMahsrafi Date: Wed, 26 Jun 2024 14:50:42 +0600 Subject: [PATCH] update logic --- Codes/1982 B - Collatz Conjecture/1982B.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) 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<