- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this article, we will learn about the solution to the problem statement given below.

**Problem statement **− Given two numbers we need to calculate gcd of those two numbers and display them.

GCD Greatest Common Divisor of two numbers is the largest number that can divide both of them. Here we follow the euclidean approach to compute the gcd i.e. to repeatedly divide the numbers and stop when the remainder becomes zero. Here we extend the algorithm based on previous values obtained in recursion.

Now let’s observe the solution in the implementation below −

# extended Euclidean Algorithm def gcdExtended(a, b, x, y): # Base Case if a == 0 : x = 0 y = 1 return b x1 = 1 y1 = 1 # storing the result gcd = gcdExtended(b%a, a, x1, y1) # Update x and y with previous calculated values x = y1 - (b/a) * x1 y = x1 return gcd x = 1 y = 1 a = 11 b = 15 g = gcdExtended(a, b, x, y) print("gcd of ", a , "&" , b, " is = ", g)

gcd of 11 & 15 is = 1

All the variables are declared in the local scope and their references are seen in the figure above.

In this article, we have learned about how we can make a Python Program for Extended Euclidean algorithms

- Related Questions & Answers
- C Program for Extended Euclidean algorithms?
- Python Program for Basic Euclidean algorithms
- C Program for Basic Euclidean algorithms?
- C++ Program to Implement Extended Euclidean Algorithm
- Euclidean Algorithm for calculating GCD in JavaScript
- Introduction to Algorithms for Mathematical Problems
- Calculating Euclidean distance using SciPy
- Rebalancing Algorithms
- Sudoku Solving algorithms
- Algorithms and Complexities
- Adaptive Routing Algorithms
- Different Encryption Algorithms
- Extended Inter-Frame Spacing (EIFS)
- Preparing encoding and decoding algorithms for shortening URLs in JavaScript
- Python Program for QuickSort

Advertisements