Given three integers. You have to find the LCM of given 3 numbers.

First line contains three integers separated by space.

Returns the LCM of 3given numbers.

Example 1:

Input

1 3 2

Output

6

Example 2:

Input

2 4 8

Output

8

Example 3:

Input

3 5 7

Output

105

Login to see Discussion

Approach 1: using while and if

Step-i) get the minimum of two numbers and store it in the variable

Step-ii) divide min by num1 and num1 and get the remainder

Step-iii) if remainder of both the divisions is 0 return minimum

Step-iv) else increment min

Step-v) Repeat step ii, iii and iv until remainder is 0 for both the divisions

Time Complexity: O(n2-n1) where n2 and n1 are given numbers and when n2 is big

Space Complexity: O(1)

Approach 2: using gcd

Step-i) first get the gcd of two numbers

(Note: algorithm to calculate gcd is already explained if you haven't visited it please visit

that and come back)

Step-ii) now multiply num1 and num2 and divide with the gcd of those two numbes

Step-iii) return the result

Time Complexity: O(logn) as finding gcd is logn rest is only formula

Space Complexity: O(1)

**Note : **

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

Login to see Solution