50. LCM of Two Numbers
Difficulty: easy · Math, Number Theory
Problem
Given two positive integers `a` and `b`, print their least common multiple (the smallest positive integer divisible by both).
Input
A single line containing two integers `a` and `b` separated by a space.
Output
Print `lcm(a, b)`.
Example 1
Input: 4 6 Output: 12
Explanation: Multiples of 6 are 6, 12, ...; 12 is the first that is also divisible by 4.
Example 2
Input: 7 13 Output: 91
Explanation: 7 and 13 share no factor, so the LCM is 7 * 13 = 91.
Constraints
- 1 <= a, b <= 10^9
Solutions are judged against 2 sample and 10 hidden tests. Sign in to solve it · All problems