Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Issue With Finding GCD of Two Numbers

Hello everyone,


I am having trouble finding the GCD of two numbers using Euclid’s algorithm. According to this article, the algorithm works by dividing the larger number by the smaller number and then taking the remainder. The algorithm continues until the remainder is 0 and then the smaller number is the GCD. 

I wrote a program to do this using Python: 

def gcd(a, b): 
    if(b == 0): 
        return a 
    else: 
        return gcd(b, a % b) 

However, when I tested it with two large numbers, the program kept running for a long time and ultimately crashed. I'm not sure what I'm doing wrong. 

Any help or advice would be greatly appreciated. 

Thank you!

Sign In or Register to comment.