#B. Two Buttons .
B.两个按钮。
time limit per test: 2 seconds
每次测试的时间限制:2秒
memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节
input: standard input
输入:标准输入
output: standard output
产出:标准产出
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
整数。单击红色按钮后,设备将显示的数字乘以2。单击蓝色按钮后,设备从
the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrariy large
显示上的数字。如果在某个时候这个数字不再是正数,设备就会崩溃。这个显示器可以显示出任意的大。
numbers. Initially, the display shows number n.
数字。最初,显示数字n。
Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?
鲍勃想在显示器上弄到号码M。为了达到这一结果,他必须进行多少次点击?
Input
输入
The first and the only line of the input contains two distinct integers n and m(1≤n, m≤10*), separated by a space .
输入的第一行和唯一一行包含两个不同的整数n和m(1≤n,m≤10*),用空格分隔。
Output
输出量
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.
打印一个数字一,最小的次数,需要按下按钮,以使数字m从数字n。
int n,m;
int dp[100007];
*(目标大的话)如果目标偶数就除二
int main() {
string s;
int man = 0, ans = 0, n, m;
int a[1000];
while(cin >> n >> m) {
ans = 0;
if(n > m) {
cout<<n - m<<endl;
} else {
while(n < m) {
if(m % 2 != 0) {
m++;
ans++;
}
m /= 2;
ans++;
}
ans+=n-m;
cout<<ans<<endl;
}
}
}