Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Varian and Mateo are alchemists trying to outdo each other. Varian has created a magical device that converts lead into gold, and it works as
Varian and Mateo are alchemists trying to outdo each other. Varian has created a magical device that converts lead into gold, and it works as follows. It has two receptacles. In the first, he places lead bars, in the second, he places one gold bar, and after muttering a magical incantation, the amazing device replicates whatever is in receptacle as many times as there are lead bars in receptacle Unfortunately though, there is a price to all this magic, and one of the lead bars in receptacle gets consumed see figure below Varian doesn't mind too much though, because his device is built robustly, and he can just use it again with all the gold he already has in receptable and the lead bars in receptacle
image
Mateo has only recently completed his apprenticeship and wants to prove that he is just as good as Varian, so upon seeing Varian's demonstration, claims that he can do just as well. Mateo is actually quite brilliant and succeeds at making a device that resembles Varian's both in appearance and behaviour. Moreover, he has made an improvement, and his machine does not consume the lead bar that Varian's does see figure below Unfortunately though, it turns out that Mateo's machine has a limited number of uses before it explodes in a massive ball of flame. There really is no "free lunch"
image
Both Varian and Mateo start with a single gold bar, but different numbers of lead bars. Varian invokes his device as many times as he can until he runs out of lead bars. Mateo is very careful not to destroy his machine, so he uses it sparingly, but he still wants to outdo Varian.
Given the number of lead bars that each starts with, can you determine the minimum number of times Mateo will need to invoke his device in order to end with more gold bars than Varian?
Input Format
One line containing two integers and to denote the number of lead bars that Varian and Mateo start with respectively.
Constraints
Output Format
A single line containing the minimum number of steps Mateo needs to exceed Varian's gold.
Sample Input
Sample Output
Explanation
Varian starts with lead bars, so he gets to invoke his device twice. After the first time, he will have lead bar left and gold bars. After the second invocation, he gets gold bars for each lead bar, but he has only left, so he ends up with gold bars in total and no lead bars
Mateo starts with lead bars, so after just a single invocation, he will have gold bars, which is more than Varian was able to produce, so Mateo stops after only invocation of his device.
Sample Input
Sample Output
Explanation
Varian starts with lead bars, and after the first invocation he has lead bars and gold bars. After the second invocation, he has lead bars and gold bars; after the third, he has lead and gold bars, so he ends up with gold bars by the time he runs out of lead bars.
Mateo starts with lead bars, so after the first invocation of his device, he will have gold bars. He still has his lead bars though, so after the second invocation, he has gold bars; but he still has not exceeded Varian's gold bars yet, so he would need to continue to invoke his device. After one more time, he would then have gold bars, which would exceed Varian's total.
So Mateo would need invocations of his device, and we output as the answer.Both Varian and Mateo start with a single gold bar, but different numbers of lead bars. Varian invokes his
device as many times as he can until he runs out of lead bars. Mateo is very careful not to destroy his
machine, so he uses it sparingly, but he still wants to outdo Varian.
Given the number of lead bars that each starts with, can you determine the minimum number of times Mateo
will need to invoke his device in order to end with more gold bars than Varian?
Input Format
One line containing two integers and to denote the number of lead bars that Varian and Mateo start with
respectively.
Constraints
Output Format
A single line containing the minimum number of steps Mateo needs to exceed Varian's gold.
Sample Input
Sample Output
Explanation
Varian starts with lead bars, so he gets to invoke his device twice. After the first time, he will have lead ba
left and gold bars. After the second invocation, he gets gold bars for each lead bar, but he has only left,
so he ends up with gold bars in total and no lead bars
Mateo starts with lead bars, so after just a single invocation, he will have gold bars, which is more than
Varian was able to produce, so Mateo stops after only invocation of his device.
Sample Input
Sample Output
Explanation
Varian starts with lead bars, and after the first invoca
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started