Greatest common divisor program - A shorter Implementation

#Credits to NPTEL MOOC, Programming, Data Structures & Algorithms #in Python by Madhavan Mukund, Chennai Mathematical Institute

def gcd(m,n):
  cf = []
  for i in range(1,min(m,n)+1):
    if (m%i) == 0 and (n%i) == 0:
      cf.append(i)
  return(cf[-1])

No comments: