Skip to main content

Posts

Showing posts with the label gcd

Finding gcd using Euclid's Algorithms

According to Euclid algorithm if we have to gcd of a & b then you can get it recursively.The recursive function can be define as:            def   gcd(a,b):                    if b==0:                           return a                    else:                           return gcd(b,a%b) In the above definition of function gcd there are no restriction on passing  parameter a,b that a should be less that b or vice versa. At the time of passing the parameter you pass b as smaller number you can save one unnecessary call. If  d=gcd(a,b) then if there are a natural number e and                                  ...