Problem Formulation:
You are tasked with finding the number of composite numbers in a given range 
[
𝐿
,
𝑅
]
[L,R] such that the number of divisors of each composite number is a prime number.

Key Points of the Problem:
Composite Numbers: Composite numbers are integers greater than 1 that are not prime; they have more than two distinct divisors.
Divisor Count: For each composite number, determine how many divisors it has.
Prime Divisor Count: Only count those composite numbers whose divisor count is a prime number.
Solution Idea and Approach:
The approach is built on the following key steps:

Generate Primes Up to 
𝑅
R
​
 :

Use the Sieve of Eratosthenes to find all prime numbers up to 
𝑅
R
​
 . These primes will be used to factorize numbers efficiently and count their divisors.
Identify Composites and Count Divisors:

Iterate through the numbers from 
𝐿
L to 
𝑅
R.
Use the primes generated in the first step to count the divisors of each number efficiently.
Only consider numbers greater than 1 and ensure that the number is a composite by checking it against the prime list.
Check if Divisor Count is Prime:

Use another prime sieve to determine whether the divisor count of each composite number is prime.
If the divisor count is prime, increment the counter.
Skip Non-Composite Numbers:

Ensure that 1 and prime numbers are excluded from the count since the problem only concerns composites.

I have c++ code for this
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

// Function to generate a boolean array to mark primes up to n using the Sieve of Eratosthenes
vector<bool> generate_prime_sieve(int n) {
    vector<bool> is_prime(n + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i * i <= n; ++i) {
        if (is_prime[i]) {
            for (int j = i * i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    return is_prime;
}

// Function to count the number of divisors of a number n using primes up to sqrt(n)
int count_divisors(long long n, const vector<int>& primes) {
    int divisor_count = 1;
    long long num = n;
    for (int prime : primes) {
        if (prime * prime > num) {
            break;
        }
        int exponent = 0;
        while (num % prime == 0) {
            num /= prime;
            exponent++;
        }
        if (exponent > 0) {
            divisor_count *= (exponent + 1);
        }
    }
    if (num > 1) {
        divisor_count *= 2; // Account for a remaining prime factor larger than sqrt(n)
    }
    return divisor_count;
}

// Function to count composite numbers with a prime number of divisors in the range [L, R]
long long count_composites_with_prime_divisors(long long L, long long R) {
    int sqrtR = sqrt(R) + 1;
    vector<bool> is_prime = generate_prime_sieve(sqrtR); // Sieve to identify primes up to sqrt(R)
    vector<int> primes; // List of small primes for factorization
    for (int i = 2; i <= sqrtR; ++i) {
        if (is_prime[i]) {
            primes.push_back(i);
        }
    }

    // Create a prime lookup up to a reasonable divisor count limit
    vector<bool> is_prime_divisor_count = generate_prime_sieve(1000); // 1000 is a safe upper bound for divisor counts

    long long count = 0;
    for (long long i = L; i <= R; ++i) {
        if (i <= 1 || (i > 1 && is_prime[i])) {
            continue; // Skip 1 and prime numbers
        }
        int divisor_count = count_divisors(i, primes);
        if (diviso