Open the context
Choose the project folder and name the files or behavior involved.
List all primes up to an inclusive integer limit using a sieve capped at 1000000. Check limits zero, one and two, a square composite and the upper bound, rejecting negative, fractional or Boolean limits before allocating the sieve.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
from math import isqrt
def primes_through(limit):
if type(limit) is not int or not 0 <= limit <= 1000000:
raise ValueError("limit.range")
sieve = bytearray([1]) * (limit + 1)
sieve[0] = 0
if limit >= 1:
sieve[1] = 0
for p in range(2, isqrt(limit) + 1):
if sieve[p]:
for multiple in range(p * p, limit + 1, p):
sieve[multiple] = 0
return [i for i, prime in enumerate(sieve) if prime]The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.