```json { "documents": [ { "data": "def sieve_of_eratosthenes(limit):\n \"\"\"\n Generate all prime numbers up to the given limit using the Sieve of Eratosthenes algorithm.\n \"\"\"\n is_prime = [True] * (limit + 1)\n p = 2\n while (p * p <= limit):\n if (is_prime[p] == True):\n for i in range(p * p, limit + 1, p):\n is_prime[i] = False\n p += 1\n prime_numbers = [p for p in range(2, limit + 1) if is_prime[p]]\n return prime_numbers\n\n\ndef first_n_primes(n):\n \"\"\"\n Calculate the first n prime numbers using the Sieve of Eratosthenes algorithm.\n \"\"\"\n # Estimate an upper limit for the nth prime number using the approximation n * log(n * log(n))\n # This is a rough estimate and ensures we have a high enough limit to find the first n primes.\n import math\n if n < 6:\n limit = 15\n else:\n limit = int(n * math.log(n * math.log(n)))\n primes = sieve_of_eratosthenes(limit)\n return primes[:n]\n\n# Example usage:\nfirst_1000_primes = first_n_primes(1000)\nprint(first_1000_primes)\n", "mimeType": "text/plain", "comment": "This function calculates the first 1000 prime numbers using the Sieve of Eratosthenes algorithm." } ], "continue": false } ```