SSieveFern
Workflows

Coding workflows · Bounded prime sieves

03
Built around your work

A concrete starting point

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.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Bounded prime sieves

A concrete starting point
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.

AI coding workspace

Your next change starts here.

Get the Windows app ↗