LCM of two numbers

Beginner Problems Basic Maths Easy
  • Fun Fact: The concept of finding the Lowest Common Multiple (LCM) in this problem is commonly applied in real world scheduling and timer systems
  • For example, in operating systems, different tasks or processes can have different intervals or frequencies of operation
  • To ensure smooth co-existence, the system must determine a common time frame to accommodate all these processes
  • That common time frame is often calculated as the LCM of all the different intervals
  • Therefore, the concept of LCM is of fundamental importance in operating system design and other time-dependent systems

You are given two integers n1 and n2. You need find the Lowest Common Multiple (LCM) of the two given numbers. Return the LCM of the two numbers.


The Lowest Common Multiple (LCM) of two integers is the lowest positive integer that is divisible by both the integers.

Examples:

Input: n1 = 4, n2 = 6

Output: 12

Explanation: 4 * 3 = 12, 6 * 2 = 12.

12 is the lowest integer that is divisible both 4 and 6.

Input: n1 = 3, n2 = 5

Output: 15

Explanation: 3 * 5 = 15, 5 * 3 = 15.

15 is the lowest integer that is divisible both 3 and 5.

Input: n1 = 4, n2 = 12

Constraints

  • 1 <= n1, n2 <= 1000

Hints

  • Test-1

Company Tags

TCS Cognizant Accenture Infosys Capgemini Wipro IBM HCL Tech Mahindra MindTree