gateway/test-chat/extraction/method_ai_20251004-000335/raw_result.txt
2025-10-04 02:54:28 +02:00

53 lines
No EOL
1.3 KiB
Text

To generate a list of prime numbers up to a specified number \( N \) using the Sieve of Eratosthenes algorithm, we will first implement the algorithm and then format the output as a numbered list. Let's assume \( N = 30 \) for this example.
```python
def sieve_of_eratosthenes(n):
primes = []
is_prime = [True] * (n + 1)
p = 2
while (p * p <= n):
if (is_prime[p] == True):
for i in range(p * p, n + 1, p):
is_prime[i] = False
p += 1
for p in range(2, n + 1):
if is_prime[p]:
primes.append(p)
return primes
# Example usage
N = 30
prime_numbers = sieve_of_eratosthenes(N)
```
Now, let's format these prime numbers as a numbered list:
```plaintext
1. 2
2. 3
3. 5
4. 7
5. 11
6. 13
7. 17
8. 19
9. 23
10. 29
```
Here is the JSON response with the formatted list:
```json
{
"documents": [
{
"data": "1. 2\n2. 3\n3. 5\n4. 7\n5. 11\n6. 13\n7. 17\n8. 19\n9. 23\n10. 29",
"mimeType": "text/plain",
"comment": "Prime numbers up to 30 using the Sieve of Eratosthenes."
}
],
"continue": false
}
```
This JSON structure contains the prime numbers up to 30, formatted as a numbered list in plain text. If you need primes up to a different number \( N \), you can adjust the value of \( N \) in the code and regenerate the list.