https://codeforces.com/problemset/problem/520/B Editorial from blog- Its quite simple . First understand if m<n then ans is n-m else make m less than or equal to n by dividing it by 2 , increase the count by one and if at any moment it becomes odd increase the count by 1 and increase m by 1 . e.g 4 17 1. 17->18 2. 18->9 3. 9->10 4. 10->5 5. 5->6 6. 6->3 then 3 is smaller than 4 so ans is 6+(4-3) = 7 * Fully reverse of what the question said to do and have a alternative main solution using breadth-first search.
Comments
Post a Comment