Python Program for GCD of more than two (or array) numbers 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)) = gcd(gcd(a, b),…
Read more
Python Program for Maximum height when coins are arranged in a triangle We have N coins which need to arrange in form of a triangle, i.e. first row will have 1 coin, second row will have 2 coins and so on, we need to tell maximum height which we can achieve by using these N…
Read more
Python Program for Common Divisors of Two Numbers Given two integer numbers, the task is to find count of all common divisors of given numbers? Input : a = 12, b = 24 Output: 6 // all common divisors are 1, 2, 3, // 4, 6 and 12 Input : a = 3, b =…
Read more
Python Program for Extended Euclidean algorithms # Python program to demonstrate working of extended # Euclidean Algorithm # function for extended Euclidean Algorithm def gcdExtended(a, b, x, y): # Base Case if a == 0 : x = 0 y = 1 return b x1 = 1 y1 = 1 # To store…
Read more
Python Program for Basic Euclidean algorithms # Python program to demonstrate Basic Euclidean Algorithm # Function to return gcd of a and b def gcd(a, b): if a == 0 : return b return gcd(b%a, a) a = 10 b = 15 print(“gcd(“, a , “,” , b, “) = “,…
Read more