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
Sasha's bank account earns 4% simple interest. How much must she deposit in the account today if she wants it to be worth $1,000
Serhud [2]

If Sasha wants her account to be worth $1,000 in 5 years, then she must deposit $833.34.

<h3>What is simple interest?</h3>

Simple interest is a method of calculating interest on an amount for n period of time with a rate of interest of r. It is calculated with the help of the formula,

SI = PRT

where SI is the simple interest, P is the principal amount, R is the rate of interest, and T is the time period.

Sasha's bank account earns 4% simple interest. Therefore, if she wants it to be worth $1,000 in 5 years then the principal amount must be,

Account balance = PRT + P

$1,000 = P[(0.04×5)+1]

$1,000 = 1.2 P

P = $833.34

Hence, if Sasha wants her account to be worth $1,000 in 5 years, then she must deposit $833.34.

Learn more about Simple Interest:

brainly.com/question/2793278

#SPJ1

5 0
2 years ago
The product of two consecutive negative integers is 600. What is the value of the lesser integer?
lapo4ka [179]
X ·( x + 1 ) = 600
x² + x = 600
x² + x - 600 = 0
x_{12} = \frac{-1+/- \sqrt{1+2400} }{2}= \frac{-1+/- \sqrt{2401} }{2}= \\  =\frac{-1+/-50}{2}
x = ( - 1 - 49 ) / 2 = - 50 : 2 = - 25
x = - 25,  x + 1 = - 24
( - 25 ) · ( - 24 ) = 600
Answer:
C )   - 25
8 0
3 years ago
Read 2 more answers
I NEED HELP , 10 POINTS ON THE LINE !
aksik [14]

Answer:

ut you can consider it to be 25 41

4 0
3 years ago
Factor 18v⁹+33v⁸+14v⁷ completely ​
marin [14]

Answer:

v^{7} x (6v+7) x (3v+2)

Step-by-step explanation:

18v^9 + 33v^8 +14v^7

Factor out v^7 from the expression

v^7 x (18v^2+33v+14)

write 33v as a sum

v^7 x (18v^2+21v+12v+14)                  *like this 21v+12v

Factor out 3v from the expression

v^7 x (3v x (6v+7)+12v+14)

Factor out 2 from the expression

c^7 x (3v x (6v+7)+2(6v+7)

Factor out 6v+7 from the expression

v^7 x (6v+7) x (3v+2)

8 0
3 years ago
Lauren coordinates a construction projects for a cement company. A government project requires constructing two rectangular conc
I am Lyosha [343]

Answer:

7

Step-by-step explanation:

Total concrete for slabs

24 * 24 * 1 = 576 ft³

Additional 20 %

By rule of three      

if     576       ⇒    100

        x??      ⇒     20           x = 115,2

And there are 2 slabs, the total volume of concrete is:

Q(t)  = 2* (576 + 115,2 )      Q(t)  =  1382,4 ft³   (1)

If the truck can carry a maximum of 8 yd³, as 1 ft³  = 0,037 yd³

then a truck can carry a maximum of

8/ 0,037   =  216,21 ft³

Now the total quantity is 1382,4

Then  

1382,4/216,21        =  6,39

And as nobody can send a fraction of a truck , the fewest number of truck is 7

5 0
3 years ago
Other questions:
  • Perpendicular lines , If the green line is 3 over 4 what is the red line NEED answers
    11·2 answers
  • Mary roller skates with a constant speed of 8 km/h. How long will she take to travel a distance of 16 kilometres?
    14·1 answer
  • Solid fats are more likely to raise blood cholesterol levels than
    9·2 answers
  • A ball is dropped from a treetop 256 feet above the ground. How long does it take to hit the ground? (s = 16t2)
    15·2 answers
  • What is the end behavior of the graph of the polynomial function f(x) = 3x6 + 30x5 + 75x4?
    7·2 answers
  • use each of the digits 5 4 3 2 1 exactly once to create two different five digit numbers. Write each number on the line and comp
    9·1 answer
  • Can some help me with this math problem
    5·1 answer
  • Marty's cat weighs 10.4 pounds. this is 24.4 pounds less than the weight of marty's dog. how much does marty's dog weigh?
    5·1 answer
  • Solve for x. What is the value of<br><br> Pls help me
    9·1 answer
  • If the perimeter of this triangle is 15 centimeters, what is the value of n?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!