Given a number N. Find number of almost primes from 1 to . A number is called almost if it has exactly two distinct prime factors.
Note: The numbers can have any number of non-prime factors but should have exactly two prime factors.
Input : N = 10 Output : 2 Explanation : 6, 10 are such numbers. Input : N = 21 Output : 8
An efficient solution is to find prime numbers using Sieve of Eratosthenes. And find distinct prime factors count for numbers less than N.
Please Refer: Almost Prime Numbers
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Count all prime numbers in a given range whose sum of digits is also prime
- Count of subarrays having exactly K prime numbers
- Sum of all the prime numbers with the count of digits ≤ D
- Count of numbers below N whose sum of prime divisors is K
- Count common prime factors of two numbers
- Sum of numbers in a range [L, R] whose count of divisors is prime
- Count of Double Prime numbers in a given range L to R
- Count of subsequences which consists exactly K prime numbers
- Count numbers from range whose prime factors are only 2 and 3
- Numbers in range [L, R] such that the count of their divisors is both even and prime
- Count of natural numbers in range [L, R] which are relatively prime with N
- Count all the numbers less than 10^6 whose minimum prime factor is N
- Count numbers from range whose prime factors are only 2 and 3 using Arrays | Set 2
- Count Numbers in Range with difference between Sum of digits at even and odd positions as Prime
- Queries for the difference between the count of composite and prime numbers in a given range
- Count numbers in a range having GCD of powers of prime factors equal to 1
- Count of distinct sums that can be obtained by adding prime numbers from given arrays
- Find the XOR of first N Prime Numbers
- Find three prime numbers with given sum
- Find two prime numbers with given sum
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.