Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com

Ninja And The LCM

Easy
0/40
Average time to solve is 15m
profile
Contributed by
21 upvotes
Asked in companies
Tata Consultancy Services (TCS)D.E.ShawCarWale

Problem statement

Ninja has given two numbers ‘X’ and ‘Y’. He has to find the LCM of these two numbers.

LCM (Least Common Multiple) of two numbers is the smallest number that can be divisible by both numbers.

As you are his big brother. So help Ninja in calculating the LCM.

EXAMPLE:
Input: 'X' = 2,  ‘Y’=3

Output: "6"

As “6” is the smallest number that is divisible by both 2 and 3.
Detailed explanation ( Input/output format, Notes, Images )
Constraints :
1 <= 'T' <= 1000
1 <= ‘X’ , ‘Y’ <= 10^9
Time Limit: 1 sec
Sample Input 1 :
2
2 7
6 8
Sample Output 1 :
14
24
Explanation Of Sample Input 1 :
In test case ‘1’, before 8 to 13, all numbers are not divided by both ‘2’ and ‘7’ both. So ‘14’ is the smallest number divisible by both ‘2’ and ‘7’. So LCM of ‘2’ and ‘7’ is ‘14’.
In test case ‘2’, ‘24’ is the smallest number divisible by both ‘6’ and ‘8’ so the answer is ‘24’.
Sample Input 2 :
2
8 8
6 24
Sample Output 2 :
8
24
Full screen
Console