Input: N = 3, M = 7
The least numbers greater than equals to 3 and 7 which is a multiple of 3 and 7 is 21.
Input: N = 5, M = 5
The least numbers greater than equals to 5 and 5 which is a multiple of 5 and 5 is 5.
Approach: As we know that product of two numbers equals to the product of their Greatest Common Divisor(GCD) and Least Common Multiple(LCM). So, the LCM of the two given prime numbers can be given by: .
Since the GCD two different prime numbers are 1, Therefore , and if the two given numbers are same then the LCM is the number itself.
Below is the implementation of the above approach:
Time Complexity: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Program to find sum of prime numbers between 1 to n
- Program to find Prime Numbers Between given Interval
- C/C++ Program to find Prime Numbers between given range
- Program to print first N Prime numbers
- Python program to print all Prime numbers in an Interval
- Find the XOR of first N Prime Numbers
- Find two prime numbers with given sum
- Find three prime numbers with given sum
- Find product of prime numbers between 1 to n
- Find out the prime numbers in the form of A+nB or B+nA
- Find the sum of prime numbers in the Kth array
- Find count of Almost Prime numbers from 1 to N
- Find the Product of first N Prime Numbers
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Find all the prime numbers of given number of digits
- Find two distinct prime numbers with given product
- Find sum of exponents of prime factors of numbers 1 to N
- Program to find the Nth Prime Number
- Program to find the next prime number
- Find a sequence of N prime numbers whose sum is a composite number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : AnkitRai01