<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>

import math

class Solution:
    def nonSpecialCount(self, l: int, r: int) -> int:
        # Sieve of Eratosthenes to find primes up to sqrt(r)
        def sieve(limit):
            sieve = [True] * (limit + 1)
            sieve[0] = sieve[1] = False  # 0 and 1 are not primes
            for i in range(2, int(math.sqrt(limit)) + 1):
                if sieve[i]:
                    for j in range(i * i, limit + 1, i):
                        sieve[j] = False
            return [i for i in range(2, limit + 1) if sieve[i]]
        
        # Find primes up to sqrt(r)
        limit = int(math.sqrt(r)) + 1
        primes = sieve(limit)
        
        special_count = 0
        
        # Count special numbers in the range [l, r]
        for prime in primes:
            square = prime * prime
            if l <= square <= r:
                special_count += 1
        
        # Total numbers in the range [l, r]
        total_count = r - l + 1
        
        # Non-special numbers are total numbers minus special numbers
        return total_count - special_count

17100