Given an integer N, the task is to print all the semi-prime numbers ≤ N.
A semi-prime number is an integer which can be expressed as a product of two distinct prime numbers.
For example, 15 = 3 * 5 is a semi-prime number but 9 = 3 * 3 is not.
Input: N = 20
Output: 6 10 14 15
Input: N = 50
Output: 6 10 14 15 21 22 26 33 34 35 38 39 46
Approach: For every number < N, count the number of prime factors it has. If the number of prime factors is 2 then the number is a semi-prime number as all the semi-prime numbers have only 2 prime factors.
Below is the implementation of the above approach:
6 10 14 15
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.
- Check whether a number is semiprime or not
- Print all prime numbers less than or equal to N
- Print all Strong numbers less than or equal to N
- Print all proper fractions with denominators less than equal to N
- Find all factorial numbers less than or equal to n
- Highest and Smallest power of K less than and greater than equal to N respectively
- Print all numbers less than N with at-most 2 unique digits
- Find maximum product of digits among numbers less than or equal to N
- Sum of Semi-Prime Numbers less than or equal to N
- Find all powers of 2 less than or equal to a given number
- Find all possible subarrays having product less than or equal to K
- Print a number strictly less than a given number such that all its digits are distinct.
- Print all Prime Quadruplet of a number less than it
- Print all Jumping Numbers smaller than or equal to a given value
- Numbers less than N which are product of exactly two distinct prime numbers
- C++ program to find all numbers less than n, which are palindromic in base 10 and base 2.
- Generate all palindromic numbers less than n
- Count all the numbers less than 10^6 whose minimum prime factor is N
- Largest number with maximum trailing nines which is less than N and greater than N-D
- Largest number less than N with digit sum greater than the digit sum of 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.