Open In App

Python Program for Basic Euclidean algorithms

Last Updated : 23 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
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 , "," , b, ") = ", gcd(a, b)) 

a = 31
b = 2
print("gcd(", a , "," , b, ") = ", gcd(a, b)) 

# Code Contributed By Mohit Gupta_OMG <(0_o)> 

Output: 

GCD(10, 15) = 5
GCD(35, 10) = 5
GCD(31, 2) = 1

Time Complexity: O(Log min(a, b))

Auxiliary Space: O(Log min(a, b)), due to recursion stack.

 Please refer complete article on Basic and Extended Euclidean algorithms for more details!


Article Tags :
Practice Tags :

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy