Generalized CD


Mon Feb 21 2022 19:05:26 GMT+0000 (UTC)

Saved by @vijuhiremath #python #gcd

def GCD(x, y):
		x, y = y, x % y
	return x

def generalizedGCD(nums):
	num1 = l[0]
	num2 = l[1]
	gcd = GCD(num1, num2)

	for i in range(2, len(l)):
		gcd = find_gcd(gcd, l[i])

	return gcd

The GCD of three or more numbers equals the product of the prime factors common to all the numbers, but it can also be calculated by repeatedly taking the GCDs of pairs of numbers. gcd(a, b, c) = gcd(a, gcd(b, c))