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
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Distinct Prime Factors of Array Product
- Check if a prime number can be expressed as sum of two Prime Numbers
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the XOR of Non-Prime numbers and Prime numbers of an Array
- Count prime numbers that can be expressed as sum of consecutive prime numbers
- Count of distinct sums that can be obtained by adding prime numbers from given arrays
- Find two distinct numbers such that their LCM lies in given range
- Find product of prime numbers between 1 to n
- Find the Product of first N Prime Numbers
- Find distinct integers for a triplet with given product
- Check if each element of the given array is the product of exactly K prime numbers
- Count all prime numbers in a given range whose sum of digits is also prime
- Count numbers in a given range whose count of prime factors is a Prime Number
- Count ways to split N! into two distinct co-prime factors
- Find two prime numbers with given sum
- Check if all sub-numbers have distinct Digit product
- Check if N can be expressed as product of 3 distinct numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.