Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
22
Task/Least-common-multiple/Python/least-common-multiple-3.py
Normal file
22
Task/Least-common-multiple/Python/least-common-multiple-3.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
from prime_decomposition import decompose
|
||||
try:
|
||||
reduce
|
||||
except NameError:
|
||||
from functools import reduce
|
||||
|
||||
def lcm(a, b):
|
||||
mul = int.__mul__
|
||||
if a and b:
|
||||
da = list(decompose(abs(a)))
|
||||
db = list(decompose(abs(b)))
|
||||
merge= da
|
||||
for d in da:
|
||||
if d in db: db.remove(d)
|
||||
merge += db
|
||||
return reduce(mul, merge, 1)
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
print( lcm(12, 18) ) # 36
|
||||
print( lcm(-6, 14) ) # 42
|
||||
assert lcm(0, 2) == lcm(2, 0) == 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue