Skip to content

Instantly share code, notes, and snippets.

@SharanSMenon
Created April 21, 2018 17:08
Show Gist options
  • Save SharanSMenon/c85de34d49f1935d6f4340112327b5ca to your computer and use it in GitHub Desktop.
Save SharanSMenon/c85de34d49f1935d6f4340112327b5ca to your computer and use it in GitHub Desktop.
def gcd(a, b):
"""
An efficient algorithm to compute GCD \n
a is a number \n
b is the other number \n
no other arguments
"""
if b == 0:
return a
ap = a % b
return gcd(b, ap)
def lcm(a, b):
"""
An efficient algorithm to calculate LCM \n
This algorithm works efficiently.
"""
return a * b / gcd(a, b)
@SharanSMenon
Copy link
Author

Important edit

Replace LCM function with this:

def lcm(a, b):
    """
    An efficient algorithm to calculate LCM \n
    This algorithm works efficiently.
    """
    return a * b // gcd(a, b)

@SharanSMenon2
Copy link

More detail on edit

It is being changed to integer multiplication.
The line that needs to be changed is this

return a * b / gcd(a, b)

With this

return a * b // gcd(a, b)

Be awesome
-Sharan Sajiv Menon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment