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 = 10b = 15print("gcd(", a , "," , b, ") = ", gcd(a, b)) a = 35b = 10print("gcd(", a , "," , b, ") = ", gcd(a, b)) a = 31b = 2print("gcd(", a , "," , b, ") = ", gcd(a, b)) # Code Contributed By Mohit Gupta_OMG <(0_o)> |
chevron_right
filter_none
Output:
GCD(10, 15) = 5 GCD(35, 10) = 5 GCD(31, 2) = 1
Time Complexity: O(Log min(a, b))
Please refer complete article on Basic and Extended Euclidean algorithms for more details!
Recommended Posts:
- Python Program to print digit pattern
- Python | Extract key-value of dictionary in variables
- Python program to convert time from 12 hour to 24 hour format
- Google Chrome Dino Bot using Image Recognition | Python
- Python | Animated Banner showing 'GeeksForGeeks'
- Python | Segregate list elements by Suffix
- Python Program for Selection Sort
- Python Program for Bubble Sort
- Python Program for Insertion Sort
- Python Program for Heap Sort
- Python Program for Counting Sort
- Python Program for Radix Sort
- Python Program for n-th Fibonacci number
- Python Program for Counting Sort
- Python Program for ShellSort



