<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p>

<p>A number is called <strong>special</strong> if it has exactly 2 <strong>proper divisors</strong>. For example:</p>

<ul>
	<li>The number 4 is <em>special</em> because it has proper divisors 1 and 2.</li>
	<li>The number 6 is <em>not special</em> because it has proper divisors 1, 2, and 3.</li>
</ul>

<p>Return the count of numbers in the range <code>[l, r]</code> that are <strong>not</strong> <strong>special</strong>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">l = 5, r = 7</span></p>

<p><strong>Output:</strong> <span class="example-io">3</span></p>

<p><strong>Explanation:</strong></p>

<p>There are no special numbers in the range <code>[5, 7]</code>.</p>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">l = 4, r = 16</span></p>

<p><strong>Output:</strong> <span class="example-io">11</span></p>

<p><strong>Explanation:</strong></p>

<p>The special numbers in the range <code>[4, 16]</code> are 4 and 9.</p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= l &lt;= r &lt;= 10<sup>9</sup></code></li>
</ul>

class Solution:
    def nonSpecialCount(self, l: int, r: int) -> int:
        def sieve_of_eratosthenes(max_num):
            is_prime = [True] * (max_num + 1)
            is_prime[0] = is_prime[1] = False  # 0 和 1 不是质数
            p = 2
            while p * p <= max_num:
                if is_prime[p]:
                    for i in range(p * p, max_num + 1, p):
                        is_prime[i] = False
                p += 1
            primes = [p for p, is_prime in enumerate(is_prime) if is_prime]
            return primes

        max_check = int(r**0.5) + 1
        primes = sieve_of_eratosthenes(max_check)
        
        # 生成所有在范围 [l, r] 内的特殊数
        special_numbers = set()
        for p in primes:
            special_number = p * p
            if special_number > r:
                break
            if special_number >= l:
                special_numbers.add(special_number)
        
        # 计算非特殊数的数量
        total_numbers = r - l + 1
        count_special = len(special_numbers)
        
        # 非特殊数的数量 = 总数 - 特殊数的数量
        return total_numbers - count_special
17300