Given a number N (greater than 2 ). The task is to find two distinct prime numbers whose product will be equal to the given number. There may be several combinations possible. Print only first such pair.
If it is not possible to express N as a product of two distinct primes, print “Not Possible”.
Input : N = 15 Output : 3, 5 3 and 5 are both primes and, 3*5 = 15 Input : N = 39 Output : 3, 13 3 and 13 are both primes and, 3*13 = 39
The idea is to find all the primes less than or equal to the given number N using Sieve of Eratosthenes. Once we have an array that tells all primes, we can traverse through this array to find a pair with a given product.
Below is the implementation of the above approach:
- Numbers less than N which are product of exactly two distinct prime numbers
- Find product of prime numbers between 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
- Distinct Prime Factors of Array Product
- Exactly n distinct prime factor numbers from a to b
- Check if all sub-numbers have distinct Digit product
- Number of distinct prime factors of first n natural numbers
- Product of all prime numbers in an Array
- Count of distinct sums that can be obtained by adding prime numbers from given arrays
- Check if each element of the given array is the product of exactly K prime numbers
- Sum and product of k smallest and k largest prime numbers in the array
- Check if product of array containing prime numbers is a perfect square
- Find N distinct numbers whose bitwise Or is equal to K
- Find two numbers with sum and product both same as N
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.