Playing With Numbers
All submissions for this problem are available.
Chef’s brother has visited the Chef during his summer vacation. Chef’s brother loves to play with numbers. So Chef gave him 2 numbers A and B. Chef asked his brother to find the minimum number of steps required to reach B from A given only the following operations can be performed any number of times:
- Decrement the current number by 1
- Increment the current number by 3
- Multiply the current number by 2
Chef’s brother found this problem very easy and asked you to solve it. Can you solve this problem for him?
- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
- The first and only line of each test case contains two space-separated integers A and B.
For each test case, output a single line containing the answer.
- 1 ≤ T ≤ 100
- 0 ≤ A,B ≤ 2*103
ExampleInput: 2 4 7 0 10 Output: 1 4
Test case 1. You can reach from 4 to 7 in just one step by adding 3.
Test case 2. It is possible to reach 10 from 0 in just 4 steps. 0 -> 3 -> 6 -> 5 -> 10 First add 3 to the number 2 times to get 6, then subtract 1 from it to get 5, and then just double it to get 10.
|Tags||bfs, encoding, graph, horsbug98, horsbug98|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS|
Fetching successful submissions