A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
18
Task/Least-common-multiple/Python/least-common-multiple-4.py
Normal file
18
Task/Least-common-multiple/Python/least-common-multiple-4.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
>>> def lcm(p,q):
|
||||
p, q = abs(p), abs(q)
|
||||
m = p * q
|
||||
if not m: return 0
|
||||
while True:
|
||||
p %= q
|
||||
if not p: return m // q
|
||||
q %= p
|
||||
if not q: return m // p
|
||||
|
||||
|
||||
>>> lcm(-6, 14)
|
||||
42
|
||||
>>> lcm(12, 18)
|
||||
36
|
||||
>>> lcm(2, 0)
|
||||
0
|
||||
>>>
|
||||
Loading…
Add table
Add a link
Reference in a new issue