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

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

some-alt