Greatest Common Divisor and Least Common Multiple
InterviewTime limit1sMemory limit128 MB
Given the gcd and lcm of two unknown natural numbers, find the pair with the smallest sum satisfying both conditions.
- Level
Easy3 of 10
- Topics
- Number theory, Math, Brute force
- Solved
- No attempts yet
Problem
You are given the greatest common divisor and the least common multiple of two natural numbers. Find two natural numbers whose greatest common divisor and least common multiple are exactly those two given values.
There can be several valid pairs. For instance, if the greatest common divisor is 6 and the least common multiple is 180, possible pairs include (12, 90), (30, 36), (18, 60), and (6, 180). Among all valid pairs, choose the one with the smallest sum.
Write a program that finds the two natural numbers.
Input
The first line contains two natural numbers G and L separated by a space. G is the greatest common divisor of the two numbers to find, and L is their least common multiple. Both numbers are between 2 and 100,000,000, inclusive.
Output
Print the two natural numbers that satisfy the condition, in increasing order, separated by a space. If there are multiple valid pairs, print the pair whose sum is as small as possible.