47. When Will the Buses Meet? (LCM)

Acceptance — 0 accepted 0 submissions

Easy
GCDLoopsMath
No companies listed
At Majestic bus stand, Bus A leaves every a minutes and Bus B leaves every b minutes. Both left together just now.

After how many minutes will they leave together again? That is the LCM (least common multiple) of a and b.

Input Format
A single line with two integers a and b.

Output Format
Print the LCM of a and b.

Constraints
• 1 ≤ a, b ≤ 10^5
• The answer can be up to 10^10. Use long long or long.

Example 1

Input
4 6
Output
12

Explanation Bus A: 4, 8, 12… Bus B: 6, 12… They meet at 12.

Example 2

Input
5 7
Output
35

Explanation No common factor, so 5 × 7 = 35.

Example 3

Input
10 5
Output
10

Explanation Every time B leaves at a multiple of 10, A also leaves, so 10.

Acceptance —
Accepted 0
Submissions 0
Auto-save
Saved Ln 1, Col 1
Submit a solution to see its status here.
Input
Expected Output
12
No results yet
Run your code to test it against the sample cases.
Problem List