Logic Building
# Take two numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
# Find LCM
larger = max(a, b)
lcm = larger
while True:
if lcm % a == 0 and lcm % b == 0:
break
lcm += larger
print(f"LCM of {a} and {b} is {lcm}")Output
Enter first number: 12 Enter second number: 18 LCM of 12 and 18 is 36
Find smallest number divisible by both.
Key Concepts:
- Start from larger number
- Check multiples of larger number
- First number divisible by both is LCM