Question

We discuss the Euclidean algorithm that finds the greatest common divisor of 2 numbers u and...

We discuss the Euclidean algorithm that finds the greatest common divisor of 2 numbers u and v. We want to extend and compute the gcd of n integers gcd⁡(u1,u2,….un). One way to do it is to assume all numbers are non-negative, so if only one of if uj≠0 it is the gcd. Otherwise replace uk by uk mod uj  for all k≠j where uj is the minimum of the non-zero elements (u’s). The algorithm can be made significantly faster if one consider the identity:

gcdu1,u2….un=gcd⁡(u1,gcdu2,u3,..un).

Then we may calculate gcdu1,u2….un with following algorithm:

            Step 1. set d←un, j←n-1

            Step 2. if d≠1 and j>0 setgcduj,dand j=j-1 and repeat Step 2.

Else d=gcd(u1,u2,…un).

What is the smallest value of un such that the calculation of: gcd(u1,u2,..., un)
by steps Step 1 and Step 2 (given above) requires N divisions, if Euclid’s algorithm is used throughout? Assume that N ≥ n.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

This java code can be used to find the gcd of array of elements:

CODE:

public class GCD{
static int gcd(int x,int y) //GCD of two numbers
{
if (x==0)
return y;
return gcd(y%x,x);
}
static int findgcd(int arr[], int n)//Function to find gcd of array of numbers. Ex:gcd⁡(u_1,u_2,…,u_n).
{
int result = arr[0];
for (int i=1;i<n;i++){
result=gcd(arr[i],result);

if(result==1)
{
return 1;
}
}
return result;
}
public static void main(String args[])
{
int arr[] = {2,4,6,26,45}; //Input elemets
//you can write a loop to get the inputs as per user requirement
int n=arr.length;
System.out.println(findgcd(arr,n));//Array elements and array length are passed as arguments
}
}

Add a comment
Know the answer?
Add Answer to:
We discuss the Euclidean algorithm that finds the greatest common divisor of 2 numbers u and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • We discuss the Euclidean algorithm that finds the greatest common divisor of 2 numbers u and...

    We discuss the Euclidean algorithm that finds the greatest common divisor of 2 numbers u and v. We want to extend and compute the gcd of n integers gcd⁡(u_1,u_2,….u_n). One way to do it is to assume all numbers are non-negative, so if only one of if u_j≠0 it is the gcd. Otherwise replace u_k by u_k mod u_j for all k≠j where u_j is the minimum of the non-zero elements (u’s). The algorithm can be made significantly faster if...

  • a Find the greatest common divisor (gcd) of 322 and 196 by using the Euclidean Algorithm....

    a Find the greatest common divisor (gcd) of 322 and 196 by using the Euclidean Algorithm. gcd- By working back in the Euclidean Algorithm, express the gcd in the form 322m196n where m and n are integers b) c) Decide which of the following equations have integer solutions. (i) 322z +196y 42 ii) 322z +196y-57

  • Question 1. (a) Find the greatest common divisor of 10098 and 3597 using the Euclidean Algorithm....

    Question 1. (a) Find the greatest common divisor of 10098 and 3597 using the Euclidean Algorithm. (b) Find integers a and a2 with 1009801 +3597a2 = gcd(10098,3597). (c) Are there integers bı and b2 with 10098b1 + 3597b2 = 71? Justify your answer. (d) Are there integers ci and c2 with 10098c1 + 3597c2 = 99? Justify your answer. Question 2. Consider the following congruence. C: 21.- 34 = 15 (mod 521) (a) Find all solutions x € Z to...

  • 20 points Problem 4: Extended Euclidean Algorithm Using Extended Euclidean Algorithm compute the greatest common divisor...

    20 points Problem 4: Extended Euclidean Algorithm Using Extended Euclidean Algorithm compute the greatest common divisor and Bézout's coefficients for the pairs of integer numbers a and b below. Express the greatest common divisor as a linear combination with integer coefficients) of a and b. (Do not use factorizations or inspection. Please demonstrate all steps of the Extended Euclidean Algo- rithm.) (a) a 270 and b = 219 (b) a 869 and b 605 (c) a 4930 and b-1292 (d)...

  • IN PYTHON Write a recursive function for Euclid's algorithm to find the greatest common divisor (gcd)...

    IN PYTHON Write a recursive function for Euclid's algorithm to find the greatest common divisor (gcd) of two positive integers. gcd is the largest integer that divides evenly into both of them. For example, the gcd(102, 68) = 34. You may recall learning about the greatest common divisor when you learned to reduce fractions. For example, we can simplify 68/102 to 2/3 by dividing both numerator and denominator by 34, their gcd. Finding the gcd of huge numbers is an...

  • 1. (10 points) GCD Algorithm The greatest common divisor of two integers a and b where...

    1. (10 points) GCD Algorithm The greatest common divisor of two integers a and b where a 2 b is equal to the greatest common divisor of b and (a mod b). Write a program that implements this algorithm to find the GCD of two integers. Assume that both integers are positive. Follow this algorithm: 1. Call the two integers large and small. 2. If small is equal to 0: stop: large is the GCD. 3. Else, divide large by...

  • Use the Division Algorithm to find the greatest common divisor of each pair of numbers below...

    Use the Division Algorithm to find the greatest common divisor of each pair of numbers below and determine whether each pair is rela- tively prime or not. Then reverse the process and write the gcd as a sum of multiples of the original pair. a. 12 and 15 b. 36 and 72 c. 27 and 10 d. 35 and 12

  • Cryptography Computer Security Greatest Common Divisor Assignment Instructions In software, implement the Euclidean algorithm to find...

    Cryptography Computer Security Greatest Common Divisor Assignment Instructions In software, implement the Euclidean algorithm to find the greatest common divisor of any two positive integers. It should implement the pseudocode provided in the text. It should allow the user to enter two integers.   Your program should output the intermediate values of q, r1, r2 for each step and should return the greatest common divisor. Challenge component: Allow the user's input to be zero as well as the positive integers. Provide...

  • Use R language to program Problem 1: Greatest Common Divisor (GCD) Please write two functions, g...

    Use R language to program Problem 1: Greatest Common Divisor (GCD) Please write two functions, g edi ) and gcdr , which both take two integers a, b and calculates their greatest common divisor (GCD) using the Euclidean algorithm gcdi () should do so using iteration while gcdr () should use recursion. Then write a third function, gcd(), which takes two integers a, band an optional third argument nethod which takes a charater string containing either "iterative" or "recursive", with...

  • In Assembly Language Please display results and write assembler code in (gcd.s) The Euclidean algorithm is...

    In Assembly Language Please display results and write assembler code in (gcd.s) The Euclidean algorithm is a way to find the greatest common divisor of two positive integers, a and b. First let me show the computations for a=210 and b=45. Divide 210 by 45, and get the result 4 with remainder 30, so 210=4·45+30. Divide 45 by 30, and get the result 1 with remainder 15, so 45=1·30+15. Divide 30 by 15, and get the result 2 with remainder...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT