-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calculate GCD using euclidean algo and lcm
- Loading branch information
Garvit244
committed
Oct 3, 2017
1 parent
861e5e2
commit 715bc44
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
euclid_gcd(0 is used to find the gcd of two numbers using euclidean algorithm | ||
@input: a, b numbers | ||
@output gcd(a,b) | ||
""" | ||
|
||
def euclid_gcd(a, b): | ||
if a < b: | ||
return euclid_gcd(b, a) | ||
|
||
while b != 0: | ||
(a, b) = (b, a%b) | ||
|
||
return a |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
euclid_gcd() is used to find the gcd of two numbers using euclidean algorithm | ||
@input: a, b numbers | ||
@output gcd(a,b) | ||
""" | ||
|
||
def euclid_gcd(a, b): | ||
if a < b: | ||
return euclid_gcd(b, a) | ||
|
||
while b != 0: | ||
(a, b) = (b, a%b) | ||
|
||
return a | ||
""" | ||
lcm() is used to return the least common multiple between two numbers | ||
@input: a, b numbers | ||
@output: lcm(a, b) | ||
""" | ||
|
||
def lcm(a, b): | ||
gcd = euclid_gcd(a, b) | ||
return (a*b)/gcd |