Design and develop an efficient algorithm to find the list of prime numbers in the range 501 to 2000. What is the complexity of this algorithm?


import math

def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False
    return True

def primes_in_range(start, end):
    return [n for n in range(start, end + 1) if is_prime(n)]

# Usage
primes = primes_in_range(501, 2000)
print(primes)

Time Complexity: O(NN)O(N \sqrt{N}), where N=20005011500N = 2000 - 501 \approx 1500
أحدث أقدم