Given a number
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(
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.
- First element of every K sets having consecutive elements with exactly K prime factors less than N
- Count number of integers less than or equal to N which has exactly 9 divisors
- Number less than equals to N with maximum product of prime factors
- Sum and Product of all the nodes which are less than K in the linked list
- Count number less than N which are product of perfect squares
- Find Largest Special Prime which is less than or equal to a given number
- Largest number with maximum trailing nines which is less than N and greater than N-D
- Find two distinct prime numbers with given product
- Exactly n distinct prime factor numbers from a to b
- Count numbers whose maximum sum of distinct digit-sum is less than or equals M
- Check if each element of the given array is the product of exactly K prime numbers
- Count of subsequences which consists exactly K prime numbers
- Find maximum product of digits among numbers less than or equal to N
- Print all prime numbers less than or equal to N
- Count all the numbers less than 10^6 whose minimum prime factor is N
- Print all Semi-Prime Numbers less than or equal to N
- Sum of Semi-Prime Numbers less than or equal to N
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Find the number of distinct pairs of vertices which have a distance of exactly k in a tree
- C++ program to find all numbers less than n, which are palindromic in base 10 and base 2.
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.