A number-theoretic sieve processes many integers together by marking or updating those sharing a divisor, rather than testing each integer independently. The sieve of Eratosthenes marks composite multiples of successive prime numbers; related sieves accumulate a smallest prime factor, Euler's totient function, or Möbius function for every argument up to a bound. The useful structure is that the multiples of a fixed integer form an arithmetic progression, so one loop can update all affected entries in an array.
For example, initializing an array to true and then marking for each surviving prime number leaves precisely the prime numbers unmarked, apart from the separately excluded zero and one. Every composite number has a prime factor, which proves that every composite is eventually removed. Starting the marking at avoids work already performed by smaller prime numbers. Different sieves use different update rules and time complexity bounds; the name alone does not imply the complexity of the sieve of Eratosthenes.
An odd-only sieve stores only odd candidates, handling the prime two separately. This reduces the candidate storage and avoids marking even composites repeatedly.
A totient sieve computes the Euler totient function for many integers at once. Initialize and, for each prime , replace by for every multiple of .
A smallest prime factor sieve stores the least prime divisor for integers up to a bound . Initialize entries unset; scan primes in increasing order and fill their still-unset multiples. A composite first marked by has no smaller prime divisor, so the stored value is correct. For example, repeatedly dividing by its stored factors gives , hence . A table uses entries and accelerates repeated factorizations; the values at zero and one need a separate sentinel convention.
A number-theoretic sieve used to enumerate prime numbers by excluding composite numbers. The sieve of Eratosthenes marks multiples of each discovered prime, beginning at its square.
Choose a modulus that is a product of small primes. Every prime not dividing must be coprime to , so a search can restrict candidates to the corresponding residue classes modulo . For several linear polynomials, discard each residue class in which any required value is divisible by a selected prime. The surviving residue classes can be combined using the Chinese remainder theorem.
The wheel modulus is the product of a chosen finite set of small distinct prime numbers in wheel factorization. Except for those primes themselves, every prime candidate must lie in a residue class coprime to . For , the allowed residues are , repeating every thirty integers. The proportion retained is . Passing the wheel only avoids these small divisors; it does not certify primality, since composite values such as still pass.
A Du Jiao sieve computes a summatory arithmetic function using a Dirichlet convolution identity and memoization of repeated quotient arguments. For the Mertens function , the identity gives . Grouping equal quotients and precomputing small arguments makes this recurrence relation useful for large inputs.
The Min_25 sieve computes summatory multiplicative functions by isolating weighted prime sums and then restoring composite contributions. A useful basic form applies when for primes , the degree is small, and values on prime powers can be computed efficiently. The formulas below explain the two stages; optimized implementations differ in scheduling and cost.[ref]
Min_25 sieve explanation in the ABC370 editorial. general multiplicative-function framework, Lucy DP and Min_25 sieve sections
Use quotient arguments . There are distinct values: indices at most contribute that many, and larger indices yield values below . The floor function identity keeps later quotients in this table.
For each exponent , initialize . Process primes in increasing order, and eligible in decreasing order, applyingThis removes composites whose smallest prime factor is . The subtraction inside parentheses excludes earlier primes from the possible cofactors. Decreasing ensures each smaller argument still has its pre- value. After sieving, is the desired sum of over primes up to .
To restore composites, let be the th prime and let sum over with every prime factor greater than . Set for . Otherwise its prime contribution is , and addUnique decomposition by smallest prime factor and its full exponent proves this recurrence: mixed numbers use the first term, pure powers use the second. With , and , the answer is . No complete-multiplicativity assumption is needed.
For the Euler totient function up to six, the prime contribution is . The composites add , and gives total twelve. This independently chosen small example checks that prime powers and mixed products are both counted once.
A number-theoretic sieve that processes a large search range in smaller intervals. To find primes in , first generate the primes at most , then mark their multiples in the current segment. Memory for the segment depends on its width rather than on .
An odd-only segmented sieve represents only odd integers in each bounded interval, handling the prime two separately. For an odd first represented value , array index stands for . To mark multiples of an odd prime , begin at the smallest odd multiple at least and advance by , corresponding to index stride . Base primes up to the square root of the upper endpoint suffice. The segmentation limits working storage while omitting even candidates roughly halves it again. The number one remains nonprime and must be excluded explicitly.
A number-theoretic sieve that visits each composite number exactly once, through its smallest prime factor. Keep a growing list of prime numbers; for each , generate only for stored primes . Each composite has a unique representation admitted by this rule, giving arithmetic updates up to .
Articles by others on the same topic
There are currently no matching articles.