699. LCM of Two Numbers Using Recursion

EasyRecursionRecursion

Given two positive integers a and b, compute their LCM (Least Common Multiple) using recursion. Use the relation: LCM(a, b) = (a × b) / GCD(a, b), where GCD is computed recursively via the Euclidean algorithm.

Input: Two positive integers a and b (1 ≤ a, b ≤ 10000), separated by a comma.

Output: A single integer — the LCM of a and b.

Examples

Example 1
Input: 4, 6
Output: 12
Explanation: GCD(4,6)=2. LCM=4×6/2=12.
Example 2
Input: 3, 5
Output: 15
Explanation: GCD(3,5)=1 (coprime). LCM=3×5/1=15.
Example 3
Input: 12, 18
Output: 36
Explanation: GCD(12,18)=6. LCM=12×18/6=36.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →