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 2 as many times as there are lead bars in receptacle 1. Unfortunately though, there is a price to all this magic, and one of the lead bars in receptacle 1 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 2, and the  lead bars in receptacle 1.   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 1 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").   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 pay close attention to the constraints in the uploaded photo please   Output Format A single line containing the minimum number of steps Mateo needs to exceed Varian's gold. Sample Input 0 2 3 Sample Output 0 1 Explanation 0 Varian starts with 2 lead bars, so he gets to invoke his device twice. After the first time, he will have 1 lead bar left and 2 gold bars. After the second invocation, he gets 2 gold bars for each lead bar, but he has only 1 left, so he ends up with 2 gold bars in total (and no lead bars). Mateo starts with 3 lead bars, so after just a single invocation, he will have 3 gold bars, which is more than Varian was able to produce, so Mateo stops after only 1 invocation of his device. Sample Input 1 4 3 Sample Output 1 3 Explanation 1 Varian starts with 4 lead bars, and after the first invocation he has 3 lead bars and 4 (= 1 + 1 + 1 + 1) gold bars. After the second invocation, he has 2 lead bars and 12 (= 4 + 4 + 4) gold bars; after the third, he has 1 lead and 24 (= 12 + 12) gold bars, so he ends up with 24 gold bars by the time he runs out of lead bars. Mateo starts with 3 lead bars, so after the first invocation of his device, he will have 3 gold bars. He still has his 3 lead bars though, so after the second invocation, he has 9 (= 3 + 3 + 3) gold bars; but he still has not exceeded Varian's 24 gold bars yet, so he would need to continue to invoke his device. After one more time, he would then have 9 + 9 + 9 = 27 gold bars, which would exceed Varian's total. So, Mateo would need 3 invocations of his device, and we output 3 as the answer. here is the starting code  use logs instead of factorials as recursive calls for factorial is too slow #!/bin/python3 import sys

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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 2 as many times as there are lead bars in receptacle 1. Unfortunately though, there is a price to all this magic, and one of the lead bars in receptacle 1 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 2, and the  lead bars in receptacle 1.

 

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 1 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").

 

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

pay close attention to the constraints in the uploaded photo please

 

Output Format

A single line containing the minimum number of steps Mateo needs to exceed Varian's gold.

Sample Input 0

2 3

Sample Output 0

1

Explanation 0

Varian starts with 2 lead bars, so he gets to invoke his device twice. After the first time, he will have 1 lead bar left and 2 gold bars. After the second invocation, he gets 2 gold bars for each lead bar, but he has only 1 left, so he ends up with 2 gold bars in total (and no lead bars).

Mateo starts with 3 lead bars, so after just a single invocation, he will have 3 gold bars, which is more than Varian was able to produce, so Mateo stops after only 1 invocation of his device.

Sample Input 1

4 3

Sample Output 1

3

Explanation 1

Varian starts with 4 lead bars, and after the first invocation he has 3 lead bars and 4 (= 1 + 1 + 1 + 1) gold bars. After the second invocation, he has 2 lead bars and 12 (= 4 + 4 + 4) gold bars; after the third, he has 1 lead and 24 (= 12 + 12) gold bars, so he ends up with 24 gold bars by the time he runs out of lead bars.

Mateo starts with 3 lead bars, so after the first invocation of his device, he will have 3 gold bars. He still has his 3 lead bars though, so after the second invocation, he has 9 (= 3 + 3 + 3) gold bars; but he still has not exceeded Varian's 24 gold bars yet, so he would need to continue to invoke his device. After one more time, he would then have 9 + 9 + 9 = 27 gold bars, which would exceed Varian's total.

So, Mateo would need 3 invocations of his device, and we output 3 as the answer. here is the starting code  use logs instead of factorials as recursive calls for factorial is too slow

#!/bin/python3

import sys

def countInvocations(v, m):
    # Complete this function

if __name__ == "__main__":
    v, m = input().strip().split(' ')
    v, m = [int(v), int(m)]
    count = countInvocations(v, m)
    print(count)

Problem
Varian and Mates 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 n lead bars, in the second,
he places one gold bar, and after muttering a magical Incantation, the amazing device replicates whatever is in
receptacle 2 as many times as there are lead bars in receptacle 1. Unfortunately though, there is a price to all
this magic, and one of the lead bars in receptacle 1 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 2, and then-1 lead bars in receptacle 1.
Pb
Pb
Submissions
23
1
Au
Leaderboard
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 1 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"),
Sample Output 0
Au
Discussions
介
Pb
Sample Output 1
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.
Au
Pb
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 m to denote the number of lead bars that Varian and Mateo start with
respectively.
Constraints
Au
2≤ ≤5x10
2≤ ≤ 10¹
Output Format
A single line containing the minimum number of steps Mateo needs to exceed Varian's gold.
Sample Input 0
Explanation D
Varian starts with 2 lead bars, so he gets to invoke his device twice. After the first time, he will have 1 lead bar
left and 2 gold bars. After the second invocation, he gets 2 gold bars for each lead bar, but he has only 1 left,
so he ends up with 2 gold bars in total (and no lead bars).
Mateo starts with 3 lead bars, so after just a single invocation, he will have 3 gold bars, which is more than
Varian was able to produce, so Mateo stops after only 1 Invocation of his device.
Sample Input 1
Contest ends in 4 days
..........
Submissions: 68
Max Score: 25
Difficulty: Easy
Rate This Challenge:
Mure
Transcribed Image Text:Problem Varian and Mates 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 n lead bars, in the second, he places one gold bar, and after muttering a magical Incantation, the amazing device replicates whatever is in receptacle 2 as many times as there are lead bars in receptacle 1. Unfortunately though, there is a price to all this magic, and one of the lead bars in receptacle 1 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 2, and then-1 lead bars in receptacle 1. Pb Pb Submissions 23 1 Au Leaderboard 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 1 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"), Sample Output 0 Au Discussions 介 Pb Sample Output 1 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. Au Pb 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 m to denote the number of lead bars that Varian and Mateo start with respectively. Constraints Au 2≤ ≤5x10 2≤ ≤ 10¹ Output Format A single line containing the minimum number of steps Mateo needs to exceed Varian's gold. Sample Input 0 Explanation D Varian starts with 2 lead bars, so he gets to invoke his device twice. After the first time, he will have 1 lead bar left and 2 gold bars. After the second invocation, he gets 2 gold bars for each lead bar, but he has only 1 left, so he ends up with 2 gold bars in total (and no lead bars). Mateo starts with 3 lead bars, so after just a single invocation, he will have 3 gold bars, which is more than Varian was able to produce, so Mateo stops after only 1 Invocation of his device. Sample Input 1 Contest ends in 4 days .......... Submissions: 68 Max Score: 25 Difficulty: Easy Rate This Challenge: Mure
Constraints
2≤ ≤5 x 10⁰
2 <m < 107
Output Format
A single line containing the minimum number of steps Mateo needs to exceed Varian's gold.
Sample Input 0
23
Sample Output 0
1
Explanation 0
Varian starts with 2 lead bars, so he gets to invoke his device twice. After the first time, he will have 1 lead bar
left and 2 gold bars. After the second invocation, he gets 2 gold bars for each lead bar, but he has only 1 left,
so he ends up with 2 gold bars in total (and no lead bars).
Mateo starts with 3 lead bars, so after just a single invocation, he will have 3 gold bars, which is more than
Varian was able to produce, so Mateo stops after only 1 invocation of his device.
Sample Input 1
43
Sample Output 1
3
Explanation 1
Varian starts with 4 lead bars, and after the first invocation he has 3 lead bars and 4 (= 1 +1 +1 +1) gold bars.
After the second invocation, he has 2 lead bars and 12 (= 4+4+4) gold bars; after the third, he has 1 lead and
24 (= 12 + 12) gold bars, so he ends up with 24 gold bars by the time he runs out of lead bars.
Mateo starts with 3 lead bars, so after the first invocation of his device, he will have 3 gold bars. He still has his
3 lead bars though, so after the second invocation, he has 9 (= 3+3+3) gold bars; but he still has not
exceeded Varian's 24 gold bars yet, so he would need to continue to invoke his device. After one more time, he
would then have 9+9+9=27 gold bars, which would exceed Varian's total.
So, Mateo would need 3 invocations of his device, and we output 3 as the answer.
Transcribed Image Text:Constraints 2≤ ≤5 x 10⁰ 2 <m < 107 Output Format A single line containing the minimum number of steps Mateo needs to exceed Varian's gold. Sample Input 0 23 Sample Output 0 1 Explanation 0 Varian starts with 2 lead bars, so he gets to invoke his device twice. After the first time, he will have 1 lead bar left and 2 gold bars. After the second invocation, he gets 2 gold bars for each lead bar, but he has only 1 left, so he ends up with 2 gold bars in total (and no lead bars). Mateo starts with 3 lead bars, so after just a single invocation, he will have 3 gold bars, which is more than Varian was able to produce, so Mateo stops after only 1 invocation of his device. Sample Input 1 43 Sample Output 1 3 Explanation 1 Varian starts with 4 lead bars, and after the first invocation he has 3 lead bars and 4 (= 1 +1 +1 +1) gold bars. After the second invocation, he has 2 lead bars and 12 (= 4+4+4) gold bars; after the third, he has 1 lead and 24 (= 12 + 12) gold bars, so he ends up with 24 gold bars by the time he runs out of lead bars. Mateo starts with 3 lead bars, so after the first invocation of his device, he will have 3 gold bars. He still has his 3 lead bars though, so after the second invocation, he has 9 (= 3+3+3) gold bars; but he still has not exceeded Varian's 24 gold bars yet, so he would need to continue to invoke his device. After one more time, he would then have 9+9+9=27 gold bars, which would exceed Varian's total. So, Mateo would need 3 invocations of his device, and we output 3 as the answer.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education