Question

In: Computer Science

the following is the euclid 2,300 year old algorithm for fining the greatest common divisorof two...

the following is the euclid 2,300 year old algorithm for fining the greatest common divisorof two positive integers I an J
step Operation
1. get two positive integers as input; call the larger value I and the smaller value J.
2. Divide I by J, and call rhe remainder R.
3. If R is no 0, then reset I to the value of J, reset J to the cslue of R, and go back to step 2
4. print out the answer , which the value of J.
5 stop.

go throw the algorithm using the input value 20 and 32 . After each step of the algorithm completed, give the value of I,J abd R. Determine the final output of the algorithm.

Solutions

Expert Solution

Euclid’s algorithm to find the greatest common divisor

Algorithm for finding the greatest common divisor of two positive integers “ I ” and “ J ”:

Step 1: Assign the larger integer input value as “I” and smaller integer input value as “J”.

Step 2: Divide the value of “I” with the value of “J” and set the remainder to “R”.

Step 3: If the value of “R” is not equal to zero, then assign the value of “J” to “I” and assign the value of “R” to “J” and go to step 2.

Step 4: Print the value of “J” as the greatest common divisor.

Step 5: Stop the process.

a) Analyze the above “Euclid’s algorithm” with the inputs 20 and 32 and trace the values of “ I ”, “ J ”, and “ R ” after completing each step.

Step 1: Assign the larger value 32 to “I” and smaller value 20 to “J”.

Value of “I”

32

Value of “J”

20

Value of “R”

Not assigned

Step 2:

-> Divide the value of “I” with the value of “J” and set the remainder to

“R”.

-> Dividing 32 by 20 gives the quotient as 1 and remainder “R” as 12.

Value of “I”

32

Value of “J”

20

Value of “R”

12

Step 3:

-> If the value of “R” is not equal to zero, then assign the value of “J” to “I” and assign the value of “R” to “J” and go to step 2.

-> The value of “R” is 12, which is not equal to 0. So, “I” becomes 20 and “J” becomes 12 and go to step 2.

Value of “I”

20

Value of “J”

12

Value of “R”

12

Moved to Step 2:

Step 2:

-> Divide the value of “I” with the value of “J” and set the remainder to “R”.

-> Dividing 20 by 12 gives the quotient as 1 and remainder “R” as 8.

Value of “I”

20

Value of “J”

12

Value of “R”

8

Step 3:

-> As the value of “R” is 8, which is not equal to 0. So, “I” becomes 12 and “J” becomes 8.

Value of “I”

12

Value of “J”

8

Value of “R”

8

Next iteration of step 2:

Step 2:

-> Divide the value of “I” with the value of “J” and set the remainder to “R”.

-> Dividing 12 by 8 gives the quotient as 1 and remainder “R” as 4.

Value of “I”

12

Value of “J”

8

Value of “R”

4

Step 3:

-> As the value of “R” is 4, which is not equal to 0. So, “I” becomes 8 and “J” becomes 4.

Value of “I”

8

Value of “J”

4

Value of “R”

4

Next iteration of step 2:

Step 2:

-> Divide the value of “I” with the value of “J” and set the remainder to “R”.

-> Dividing 8 by 4 gives the quotient as 2 and remainder “R” as 0.

-> As the value of “R” becomes 0, go to step 4.

Value of “I”

8

Value of “J”

4

Value of “R”

0

Step 4:

-> Print the answer.

-> Hence, the greatest common divisor of 32 and 20 is 4.

Step 5:

-> Stop the process.

Therefore, the “Euclid’s algorithm” determines the greatest common divisor among two positive integers 32 and 20 as .


Related Solutions

4. (a) Use the Euclidean algorithm to find the greatest common divisor of 21 and 13,...
4. (a) Use the Euclidean algorithm to find the greatest common divisor of 21 and 13, and the greatest common divisor of 34 and 21. (b) It turns out that 21 and 13 is the smallest pair of numbers for which the Euclidean algorithm requires 6 steps (for every other pair a and b requiring 6 or more steps a > 21 and b > 13). Given this, what can you say about 34 and 21? (c) Can you guess...
Java program: Greatest Common Divisor Write a program which finds the greatest common divisor of two...
Java program: Greatest Common Divisor Write a program which finds the greatest common divisor of two natural numbers a and b Input:  a and b are given in a line separated by a single space. Output: Output the greatest common divisor of a and b. Constraints: 1 ≤ a, b ≤ 109 Hint: You can use the following observation: For integers x and y, if x ≥ y, then gcd(x, y) = gcd(y, x%y) Sample Input 1 54 20 Sample Output...
What are the tax consequences to Euclid from the following independent events? a. Euclid bought 500...
What are the tax consequences to Euclid from the following independent events? a. Euclid bought 500 shares of common stock five years ago for $50,000. This year, Euclid receives 20 shares of common stock as a nontaxable stock dividend. What is Euclid's basis per share after this event? b. Assume instead that Euclid received a nontaxable preferred stock dividend of 20 shares. The preferred stock has a fair market value of $5,000, and the common stock, on which the preferred...
3. In mathematics, the greatest common divisor (gcd), sometimes known as the greatest common factor (gcf)...
3. In mathematics, the greatest common divisor (gcd), sometimes known as the greatest common factor (gcf) or highest common factor (hcf), of two non-zero integers, is the largest positive integer that divides both numbers. The greatest common divisor of a and b is written as gcd (a, b), or sometimes simply as (a, b). For example, gcd (12, 18) = 6, gcd (−4, 14) = 2 and gcd (5, 0) = 5. Two numbers are called co-prime or relatively prime...
I want a unique c++ code for the following. (Greatest Common Divisor) Given two integers x...
I want a unique c++ code for the following. (Greatest Common Divisor) Given two integers x and y, the following recursive definition determines the greatest common divisor of x and y, written gcd(x,y):     5 5 ± x y x y y x y y gcd( , ) if 0 gcd( , % ) if 0 Note: In this definition, % is the mod operator. Write a recursive function, gcd, that takes as parameters two integers and...
Activity 6. Write a Prolog definition of the greatest common divisor of two numbers. Then use...
Activity 6. Write a Prolog definition of the greatest common divisor of two numbers. Then use it to compute gcd(4, 10), gcd(15, 36), and gcd(25, 55). Activity 7. Write a Prolog program to find the last item in a list. give me the screenshot pls
JAVA CLASS Greatest Common Divisor Finder Enter first number: 12 Enter second number: 8 Greatest common...
JAVA CLASS Greatest Common Divisor Finder Enter first number: 12 Enter second number: 8 Greatest common divisor: 4 Continue? (y/n): y Enter first number: 77 Enter second number: 33 Greatest common divisor: 11 Continue? (y/n): y Enter first number: 441 Enter second number: 252 Greatest common divisor: 63 Continue? (y/n): n The formula for finding the greatest common divisor of two positive integers x and y follows the Euclidean algorithm as follows: 1.   Subtract x from y repeatedly until y...
A. 271 and 516 1.  Find the greatest common divisor, d, of the two numbers from part...
A. 271 and 516 1.  Find the greatest common divisor, d, of the two numbers from part A using the Euclidean algorithm. Show and explain all work. 2.  Find all solutions for the congruence ax ? d (mod b) where a and b are the integers from part A and d is the greatest common divisor from part A1. Show and explain all work.
Describe an optimal algorithm for finding the integers common to two lists of n integers each....
Describe an optimal algorithm for finding the integers common to two lists of n integers each. Evaluate how long each step in your algorithm takes using Θ-notation.
Coronado Industries has issued 2,300 shares of common stock and 460 shares of preferred stock for...
Coronado Industries has issued 2,300 shares of common stock and 460 shares of preferred stock for a lump sum of $87,000 cash. Give the entry for the issuance assuming the par value of the common stock was $5 and the fair value $30, and the par value of the preferred stock was $40 and the fair value $50. (Each valuation is on a per share basis and there are ready markets for each stock. Give the entry for the issuance...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT