Comment trouver le multiple le moins commun de deux nombres dans Python
"""
Absolute value of product of two numbers
is equal to product of GCD and LCM
gcd(a, b) * lcm(a, b) = |a*b|
=> lcm(a, b) = |a*b|/gcd(a, b)
"""
import math
def lcm(a, b):
if a == 0 or b == 0:
return 0
else:
gcd = math.gcd(a, b)
return abs(a * b) / gcd
print(int(lcm(12, 18))) # 36
Wissam