report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Operations on number - MarisaOJ: Marisa Online Judge

Operations on number

Time limit: 1000 ms
Memory limit: 256 MB
You are given an integer $n$. Each turn you can perform either operation: - Multiple $n$ by $2$. - Subtract $1$ from $n$. Find the minimum number of operations to turn $n$ to $m$. ### Input - The first line contains 2 integers $n, m$. ### Output - Print the minimum number of operations. ### Constraints - $1 \le n, m \le 10^5$. ### Example Input: ``` 2 7 ``` Output: ``` 3 ```
BFS / DFS
Connected component
Shortest path
Finding the path
Path on binary matrix
Garden
Operations on number
Bipartite graph
Tom and Jerry
Festival 1
Bamboo Forest of the Lost
Radar
Festival 2
Go
Escape from... dolls
Long leg
Lexicographically smallest path
Graph coloring
Topic
Graph
Shortest path
Rating 900
Solution (2) Solution