A scheduling tool needs, for two repeating events with periods a and b, both the largest common factor of the two periods and the first moment the two events line up again. Concretely, given two positive integers a and b, compute their greatest common divisor (the largest positive integer dividing both) and their least common multiple (the smallest positive integer that is a multiple of both).
A single line with two space-separated positive integers a and b.
A single line with two space-separated integers: the gcd of a and b, then the lcm of a and b.
Example 1
Input
12 18
Expected
6 36
Explanation
The divisors common to 12 and 18 are 1, 2, 3, 6, so the gcd is 6. The lcm is 12 * 18 / 6 = 36.
Example 2
Input
7 5
Expected
1 35
Explanation
7 and 5 are coprime, so their gcd is 1 and their lcm is 7 * 5 = 35.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →