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++

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

some-alt