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 product of prime numbers between 1 to n
- Find the Product of first N Prime Numbers
- Product of all prime numbers in an Array
- Sum and product of k smallest and k largest prime numbers in the array
- 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
- Print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime
- Print the nearest prime number formed by adding prime numbers to N
- Check if a prime number can be expressed as sum of two Prime 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 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.