def sieve_of_eratosthenes(n): """ Calculate the first n prime numbers using the Sieve of Eratosthenes algorithm. """ limit = 10000 # Start with an arbitrary limit primes = [] while len(primes) < n: limit *= 2 # Double the limit if not enough primes are found is_prime = [True] * (limit + 1) p = 2 while (p * p <= limit): if (is_prime[p] == True): for i in range(p * p, limit + 1, p): is_prime[i] = False p += 1 primes = [p for p in range(2, limit) if is_prime[p]] return primes[:n] # Calculate the first 1000 prime numbers first_1000_primes = sieve_of_eratosthenes(1000) print(first_1000_primes)