12 lines
No EOL
1.2 KiB
Text
12 lines
No EOL
1.2 KiB
Text
```json
|
|
{
|
|
"documents": [
|
|
{
|
|
"data": "def sieve_of_eratosthenes(n):\n \"\"\"\n Generate a list of prime numbers up to n using the Sieve of Eratosthenes algorithm.\n \"\"\"\n is_prime = [True] * (n + 1)\n p = 2\n while (p * p <= n):\n if (is_prime[p] == True):\n for i in range(p * p, n + 1, p):\n is_prime[i] = False\n p += 1\n prime_numbers = [p for p in range(2, n) if is_prime[p]]\n return prime_numbers\n\n# We need to find the upper limit for the sieve to ensure we get at least 1000 primes.\n# A rough estimate for the nth prime is n * log(n * log(n)), but we'll use a safe upper bound.\n\ndef find_first_1000_primes():\n upper_limit = 10000 # A safe upper limit to ensure we get at least 1000 primes\n primes = sieve_of_eratosthenes(upper_limit)\n return primes[:1000]\n\n# Get the first 1000 prime numbers\nfirst_1000_primes = find_first_1000_primes()\n\n# Print the first 1000 prime numbers\nprint(first_1000_primes)\n",
|
|
"mimeType": "text/plain",
|
|
"comment": "Python code to calculate and validate the first 1000 prime numbers using the Sieve of Eratosthenes."
|
|
}
|
|
],
|
|
"continue": false
|
|
}
|
|
``` |