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:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- 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 of subarrays having exactly K prime numbers
- Count all the numbers less than 10^6 whose minimum prime factor is N
- Count of Double Prime numbers in a given range L to R
- Sum of numbers in a range [L, R] whose count of divisors is prime
- Count common prime factors of two numbers
- Numbers in range [L, R] such that the count of their divisors is both even and prime
- Count of subsequences which consists exactly K prime numbers
- Count numbers from range whose prime factors are only 2 and 3
- Count numbers from range whose prime factors are only 2 and 3 using Arrays | Set 2
- Queries for the difference between the count of composite and prime numbers in a given range
- Count Numbers in Range with difference between Sum of digits at even and odd positions as Prime
- 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
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.