Created
April 21, 2018 17:08
-
-
Save SharanSMenon/c85de34d49f1935d6f4340112327b5ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
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
Important edit
Replace LCM function with this: