Problem Statement
A composite is a number containing at least two prime factors. For example, 15 = 3 × 5; 9 = 3 × 3; 12 = 2 × 2 × 3.
There are ten composites below thirty containing precisely two, not necessarily distinct, prime factors: 4, 6, 9, 10, 14, 15, 21, 22, 25, 26.
How many composite integers, n < 10⁸, have precisely two, not necessarily distinct, prime factors?
Approach
The solution involves:
- Generating all primes up to 10⁸/2 using Sieve of Eratosthenes
- Counting semiprimes of the form p × q where p and q are primes
- For each prime p, counting primes q where p ≤ q and p × q < 10⁸
- Using two pointers or binary search for efficient counting
- Semiprimes include both p² (same prime twice) and p × q (different primes)