Question: In Java please don't use repated code Description Mysterious Gadget Description On my way to work I find an interesting device. On the device there
In Java please don't use repated code Description
Mysterious Gadget
Description
On my way to work I find an interesting device. On the device there are five large buttons:
a RED button, a GREEN button, a BLUE button,
a WHITE button and a BLACK button. There is also a LCD panel showing a nonnegative integer. I notice that as soon as I turn on the the device, it sho ws a positive integer say n
If I click the RED button, the device will multiple the displayed number by
If I click the GREEN button, the device will multiple the displayed number by
If I click the BLUE button, the device will increment the displayed number by
If I click the BLACK button, the device will subtract from the number on the display.
If I click the WHITE button, the device will divide the displayed number by integer division
At any time if the number stops being nonnegative the device goes crazy and I have to restart it The display can show arbitrarily large numbers.
My colleague challenges me to display integer m on the display with MINIMUM number of button clicks on the device. Since we learn about trees and gr aphs this semester, I thought I'll show him what West Valley students can do by asking you to write such a program!
Note the Judge only handles console So read from the console and write to the console
Input
The first and the only line of the input contains two distinct integers n and m nm separated by a space
Output
Print a single number the minimum number of times one needs to push a button required to get the number m out of number n
Sample Input l
Sample Output
Sample Input
Sample Output your program output
Explanation: you need to push the BLACK button once, and then push the RED button once. Hence the answer is
Sample Input
Sample Output your program output
Explanation: You need to press WHITE, BLUE, BLUE to get
Hence the answer is
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
