Python Program for Extended Euclidean algorithms Last Updated : 21 Jun, 2022 Comments Improve Suggest changes Like Article Like Report Python3 # Python program to demonstrate working of extended # Euclidean Algorithm # function for extended Euclidean Algorithm def gcdExtended(a, b): # Base Case if a == 0 : return b,0,1 gcd,x1,y1 = gcdExtended(b%a, a) # Update x and y using results of recursive # call x = y1 - (b//a) * x1 y = x1 return gcd,x,y # Driver code a, b = 35,15 g, x, y = gcdExtended(a, b) print("gcd(", a , "," , b, ") = ", g) Output: gcd(35, 15) = 5 Time Complexity: O(log(max(A, B))) Auxiliary Space: O(log(max(A, B))), keeping recursion stack in mind. Please refer complete article on Basic and Extended Euclidean algorithms for more details! Comment More infoAdvertise with us Next Article Python Program for Extended Euclidean algorithms K kartik Follow Improve Article Tags : Python Practice Tags : python Similar Reads Python Program for Basic Euclidean algorithms Python3 # 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, ") = ", gcd(a, b)) a = 35 b = 10 print("gcd(", a , ", 1 min read 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), c) = gcd(gcd(a, c), b) Python # GCD of more than two (or array) numbe 1 min read Python Program for Find minimum sum of factors of number Given a number, find minimum sum of its factors.Examples: Input : 12Output : 7Explanation: Following are different ways to factorize 12 andsum of factors in different ways.12 = 12 * 1 = 12 + 1 = 1312 = 2 * 6 = 2 + 6 = 812 = 3 * 4 = 3 + 4 = 712 = 2 * 2 * 3 = 2 + 2 + 3 = 7Therefore minimum sum is 7Inp 1 min read Python Arithmetic Operators Python operators are fundamental for performing mathematical calculations. Arithmetic operators are symbols used to perform mathematical operations on numerical values. Arithmetic operators include addition (+), subtraction (-), multiplication (*), division (/), and modulus (%). OperatorDescriptionS 4 min read Python program for multiplication and division of complex number Given two complex numbers. The task is to multiply and divide them. Multiplication of complex number: In Python complex numbers can be multiplied using * operator Examples: Input: 2+3i, 4+5i Output: Multiplication is : (-7+22j) Input: 2+3i, 1+2i Output: Multiplication is : (-4+7j) Python3 # Python p 3 min read Like