1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
MariettaO [177]
3 years ago
11

5. The recursive algorithm given below can be used to compute gcd(a, b) where a and b are non-negative integer, not both zero.

Mathematics
1 answer:
s2008m [1.1K]3 years ago
6 0

Implementating the given algorithm in python 3, the greatest common divisors of <em>(</em><em>124</em><em> </em><em>and</em><em> </em><em>244</em><em>)</em><em> </em>and <em>(</em><em>4424</em><em> </em><em>and</em><em> </em><em>2111</em><em>)</em><em> </em>are 4 and 1 respectively.

The program implementation is given below and the output of the sample run is attached.

def gcd(a, b):

<em>#initialize</em><em> </em><em>a</em><em> </em><em>function</em><em> </em><em>named</em><em> </em><em>gcd</em><em> </em><em>which</em><em> </em><em>takes</em><em> </em><em>in</em><em> </em><em>two</em><em> </em><em>parameters</em><em> </em>

if a>b:

<em>#checks</em><em> </em><em>if</em><em> </em><em>a</em><em> </em><em>is</em><em> </em><em>greater</em><em> </em><em>than</em><em> </em><em>b</em>

return gcd (b, a)

<em>#if</em><em> </em><em>true</em><em> </em><em>interchange</em><em> </em><em>the</em><em> </em><em>Parameters</em><em> </em><em>and</em><em> </em><em>Recall</em><em> </em><em>the</em><em> </em><em>function</em><em> </em>

elif a == 0:

return b

elif a == 1:

return 1

elif((a%2 == 0)and(b%2==0)):

<em>#even</em><em> </em><em>numbers</em><em> </em><em>leave</em><em> </em><em>no</em><em> </em><em>remainder</em><em> </em><em>when</em><em> </em><em>divided</em><em> </em><em>by</em><em> </em><em>2</em><em>,</em><em> </em><em>checks</em><em> </em><em>if</em><em> </em><em>a</em><em> </em><em>and</em><em> </em><em>b</em><em> </em><em>are</em><em> </em><em>even</em><em> </em>

return 2 * gcd(a/2, b/2)

elif((a%2 !=0) and (b%2==0)):

<em>#checks</em><em> </em><em>if</em><em> </em><em>a</em><em> </em><em>is</em><em> </em><em>odd</em><em> </em><em>and</em><em> </em><em>B</em><em> </em><em>is</em><em> </em><em>even</em><em> </em>

return gcd(a, b/2)

else :

return gcd(a, b-a)

<em>#since</em><em> </em><em>it's</em><em> </em><em>a</em><em> </em><em>recursive</em><em> </em><em>function</em><em>,</em><em> </em><em>it</em><em> </em><em>recalls</em><em> </em><em>the function</em><em> </em><em>with </em><em>new</em><em> </em><em>parameters</em><em> </em><em>until</em><em> </em><em>a</em><em> </em><em>certain</em><em> </em><em>condition</em><em> </em><em>is</em><em> </em><em>satisfied</em><em> </em>

print(gcd(124, 244))

print()

<em>#leaves</em><em> </em><em>a</em><em> </em><em>space</em><em> </em><em>after</em><em> </em><em>the</em><em> </em><em>first</em><em> </em><em>output</em><em> </em>

print(gcd(4424, 2111))

Learn more :brainly.com/question/25506437

You might be interested in
Caillans pocket money increased from $15 per week to $20 per week.
gladu [14]
Caillan's pocket money increased 20-15=5 dollars per week, or to 20-15=1.33 of it's original amount. This is a 33% increase.
4 0
3 years ago
If y = 20 inches, z = 21 inches, and h = 11 inches, what is the area of the object?
zlopas [31]

Answer:

1742 inches squared

Step-by-step explanation:

Surface Area = 2×(20×21 + 20×11 + 21×11) = 1742 inches2

8 0
2 years ago
The Versatech Corporation has decided to produce three new products. Five branch plants now have excess production capacity. The
RSB [31]

Answer: provided in the explanation segment

Step-by-step explanation:

here i will give a step by step analysis of the question;

A: Optimization Formulation

given Xij = X no. of units of product i manufactured in Plant j, where i = 1,2,3 and J = 1,2,3,4,5

Objective function: Minimize manufacturing cost (Z)

Z = 31 X11 + 29 X12 + 32X13 + 28X14 + 29 X15 + 45 X21 + 41 X22 + 46X23 + 42X24 + 43 X25 + 38 X31 + 35 X32 + 40X33

s.t

X11 + X12 + X13 + X14 + X15 = 600

X21 + X22 + X23 + X24 + X25 = 1000

X31 + X32 + X33 = 800

X11 + X21 + X31 <= 400

X12 + X22 + X32 <= 600

X13 + X23 + X33 <= 400

X14 + X24 ​​​​​​ <= 600

X15 + X25 <= 1000

Xij >= 0 for all i,j

B:

Yes, we can formulate this problem as a transportation problem because in transportation problem we need to match the supply of source to demand of destination. Here we can assume that the supply of source is nothing but the manufacturing capability of plant and demand of destination is similar to the demand of products.

cheers i hope this helps!!

3 0
3 years ago
The sequence is recursive. Find the value of the next term in the sequence 7, 1, -5, -11, -17,
jonny [76]

Answer:

-23

Step-by-step explanation:

Each term is 6 less than the past term. Hopw this helps!

7 0
4 years ago
Read 2 more answers
A new car is purchased for \$47,000$47,000 and over time its value depreciates by one half every 4.5 years. What is the value of
Lady_Fox [76]
It’s is 47,027.5 you need to add
3 0
3 years ago
Other questions:
  • a box contains 4 white balls and 6 yellow balls a ball is drawn at random light from the box and is not replaced what is the pro
    13·2 answers
  • To get ready for a field trip students and adults were put into groups.for every 8 students in group there were 3 adults.in tota
    13·1 answer
  • Which number is a common factor of 48 and 72
    13·2 answers
  • The length of a rectangular pool is 4 meters less than twice the width. if the pool's perimeter is 88 meters, what is the width?
    11·1 answer
  • George has a rectangular wooden deck that measures 2.5 meters by 3.4 meters
    6·1 answer
  • BRAINLIEST find the equation of the line that passes through points : (-4,-2) and (-3,5)
    10·1 answer
  • If no one has asked u today I'll ask u, hows your day? have u eaten? how are u?
    14·2 answers
  • Sandy plays a matching game in order to advance to the next level, she must score at least 10 points. She scores 15 points for c
    11·1 answer
  • Byron needs at least 20 m rutes between
    7·1 answer
  • Rocío paga por un par de zapatos 94.50 soles sabiendo que es el precio y luego de los descuentos sucesivos de 10 %y 20% cuál es
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!