-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf9f1f9
commit c821661
Showing
1 changed file
with
5 additions
and
10 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 |
---|---|---|
@@ -1,19 +1,14 @@ | ||
import functools | ||
|
||
|
||
def gcd(x, y): | ||
if y == 0: | ||
return x | ||
return gcd(y, x % y) | ||
|
||
|
||
def lcm(x, y): | ||
return abs(x) / gcd(x, y) * abs(y) | ||
|
||
|
||
def lcm_many(numbers): | ||
result = numbers[0] | ||
|
||
for n in numbers[1:]: | ||
result = lcm(result, n) | ||
return result | ||
return int(abs(x) / gcd(x, y) * abs(y)) | ||
|
||
|
||
print(int(lcm_many(range(1, 21)))) | ||
print(functools.reduce(lcm, range(1, 21))) |