LCM of Two Numbers

Practice this coding question on Coding Gurukul.

Problem statement

Two maintenance alarms ring at fixed intervals and both ring at time zero. The scheduler needs the first positive time at which they ring together again. Your task Compute the least common multiple of the positive intervals a and b. Important details The required time is the smallest positive integer divisible by both intervals. Time zero is excluded even though both alarms start together. Equal intervals meet again after one interval. You can use the greatest common divisor to calculate the answer; divide before multiplying to limit intermediate growth. The final result can be much larger than either input, so use a 64-bit integer. Worked example For intervals 6 and 8, the first common positive ringing time is 24. Neither 6, 12, nor 18 is divisible by 8.

Input format

One line contains a and b.

Output format

Print lcm(a, b).

Constraints

1 <= a, b <= 1000000000.

Sample input

6 8

Sample output

24

Sign in to run or submit a solution in C++, Java or Python.