Given a number . The task is to find all such numbers less than N and are a product of exactly two distinct prime numbers.
For Example, 33 is the product of two distinct primes i.e 11 * 3, whereas numbers like 60 which has three distinct prime factors i.e 2 * 2 * 3 * 5.
Note: These numbers cannot be a perfect square.
Input : N = 30
Output : 6, 10, 14, 15, 21, 22, 26
Input : N = 50
Output : 6, 10, 14, 15, 21, 22, 26, 33, 34, 35, 38, 39, 46
- Traverse till N and check whether each number has exactly two prime factors or not.
- Now to avoid the situation like 49 having 7 * 7 product of two prime numbers, check whether the number is a perfect square or not to ensure that it has two distinct prime.
- If Step 1 and Step 2 satisfies then add the number in the vector list.
- Traverse the vector and print all the elements in it.
Below is the implementation of the above approach:
6 10 14 15 21 22 26
Time Complexity: O(*)
- Find two distinct prime numbers with given product
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- 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
- Find the Product of first N Prime Numbers
- Find product of prime numbers between 1 to n
- 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
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Distinct Prime Factors of Array Product
- Maximum sum of distinct numbers such that LCM of these numbers is 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 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.