Almost Prime
You are given an integer n.
A number is considered almost prime if it has exactly two distinct prime divisors.
Return the number of almost prime numbers in the range from 1 to n (inclusive).
Notes:
- A prime divisor of a number is a prime number that divides it exactly.
- The two prime divisors must be distinct.
- A number may contain repeated occurrences of those primes, but it should involve only exactly two distinct prime factors.
Example 1:
Input: n = 10
Output: 2
Explanation:
The almost prime numbers between 1 and 10 are:
- 6 = 2 × 3
- 10 = 2 × 5
So, the answer is 2.
Example 2:
Input: n = 21
Output: 8
Explanation:
The almost prime numbers between 1 and 21 are:
- 6 = 2 × 3
- 10 = 2 × 5
- 12 = 22 × 3
- 14 = 2 × 7
- 15 = 3 × 5
- 18 = 2 × 32
- 20 = 22 × 5
- 21 = 3 × 7
So, the answer is 8.
Now Your Turn!
Pick the correct output for the given inputInput: n = 12
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= n <= 3000