gateway/test-chat/extraction/method_ai_20251004-105415/raw_result.txt
2025-10-04 13:31:21 +02:00

12 lines
No EOL
1.8 KiB
Text

```json
{
"documents": [
{
"data": "Algorithm to calculate the first 1000 prime numbers using the Sieve of Eratosthenes:\n\n1. Initialize an empty list to store prime numbers.\n2. Set a limit for the sieve. Since the 1000th prime is 7919, a safe upper bound is 10000.\n3. Create a boolean array `is_prime` of size `limit + 1` and initialize all entries as `True`. Set `is_prime[0]` and `is_prime[1]` to `False` as 0 and 1 are not prime numbers.\n4. For each number `p` starting from 2, do the following:\n a. If `is_prime[p]` is `True`, it means `p` is a prime number.\n b. Append `p` to the list of prime numbers.\n c. Mark all multiples of `p` (starting from `p*p`) as `False` in the `is_prime` array.\n5. Continue the process until the list of prime numbers contains 1000 elements.\n6. Return the list of the first 1000 prime numbers.\n\nPseudocode:\n\nfunction calculate_first_1000_primes():\n limit = 10000\n is_prime = [True] * (limit + 1)\n is_prime[0] = is_prime[1] = False\n primes = []\n\n for p in range(2, limit + 1):\n if is_prime[p]:\n primes.append(p)\n if len(primes) == 1000:\n break\n for multiple in range(p * p, limit + 1, p):\n is_prime[multiple] = False\n\n return primes\n\n# Validation Step:\n# Ensure the length of the primes list is 1000 and the last element is 7919.\n\nprimes = calculate_first_1000_primes()\nassert len(primes) == 1000, \"The list does not contain 1000 primes.\"\nassert primes[-1] == 7919, \"The 1000th prime is incorrect.\"\n\n# If assertions pass, the list of primes is correct.",
"mimeType": "text/plain",
"comment": "This algorithm uses the Sieve of Eratosthenes to efficiently find the first 1000 prime numbers."
}
],
"continue": false
}
```