def gcd(a, b): while b: a, b = b, a % b return a def lcm(a, b): return a * b // gcd(a, b) print(gcd(24, 18)) #=> 6 print(lcm(24, 18)) #=> 72