Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.

book
Interesting Device

Bob discovered a peculiar device with a green button, a purple button, and a display showing a positive integer. Pressing the green button doubles the number on the display, while pressing the purple button subtracts one from it. If the number becomes non-positive at any point, the device will break. The display is capable of showing very large numbers. Initially, the display shows the number n. Bill wants to transform the number on the display to m.

Given integers n and m, return a minimum number of button presses required to transform number n to m.

Example 1

Input:

n = 4; m = 6

Output:

2
main.cpp

main.cpp

C++

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

some-alt