101885: [AtCoder]ABC188 F - +1-1x2

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

Takahashi has written an integer $X$ on a blackboard. He can do the following three kinds of operations any number of times in any order:

  • increase the value written on the blackboard by $1$;
  • decrease the value written on the blackboard by $1$;
  • multiply the value written on the blackboard by $2$.

Find the minimum number of operations required to have $Y$ written on the blackboard.

Constraints

  • $1 \le X \le 10^{18}$
  • $1 \le Y \le 10^{18}$
  • $X$ and $Y$ are integers.

Input

Input is given from Standard Input in the following format:

$X$ $Y$

Output

Print the answer.


Sample Input 1

3 9

Sample Output 1

3

Initially, $3$ is written on the blackboard. The following three operations can make it $9$:

  • increase the value by $1$, which results in $4$;
  • multiply the value by $2$, which results in $8$;
  • increase the value by $1$, which results in $9$.

Sample Input 2

7 11

Sample Output 2

3

The following procedure can make the value on the blackboard $11$:

  • decrease the value by $1$, which results in $6$;
  • multiply the value by $2$, which results in $12$;
  • decrease the value by $1$, which results in $11$.

Sample Input 3

1000000000000000000 1000000000000000000

Sample Output 3

0

If the value initially written on the blackboard equals $Y$, print $0$.

Input

题意翻译

### 题目描述 高桥君在黑板上写下了一个正整数 X,现在高桥君想要让这个正整数变成 Y,每一次都可以按以下三种中的任意一种方式来改变这个数: 1. 将目前黑板上的数加1。 2. 将目前黑板上的数减1。 3. 将目前黑板上的数乘以2。 现在高桥君想要知道从 X 变成 Y 的最小次数。 ### 输入格式 两个正整数 X , Y。 ### 输出格式 X 变成 Y 的最小操作的次数。 ### 说明/提示 - 1≤X≤${10^{18}}$ - 1≤Y≤${10^{18}}$

加入题单

算法标签: