codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

520B.md (1380B)


      1 Source: https://codeforces.com/problemset/problem/520/B
      2 
      3 B. Two Buttons
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number *n*.
     22 
     23 Bob wants to get number *m* on the display. What minimum number of clicks he has to make in order to achieve this result?
     24 
     25 Input
     26 
     27 The first and the only line of the input contains two distinct integers *n* and *m* (1 ≤ *n*, *m* ≤ 104), separated by a space .
     28 
     29 Output
     30 
     31 Print a single number — the minimum number of times one needs to push the button required to get the number *m* out of number *n*.
     32 
     33 Examples
     34 
     35 Input
     36 
     37 ```
     38 4 6
     39 ```
     40 
     41 Output
     42 
     43 ```
     44 2
     45 ```
     46 
     47 Input
     48 
     49 ```
     50 10 1
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 9
     57 ```
     58 
     59 Note
     60 
     61 In the first example you need to push the blue button once, and then push the red button once.
     62 
     63 In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.