Struct comlib_math::PrimeSieve[][src]

pub struct PrimeSieve(_);
Expand description

Sieve of Eratosthenes.

Sieve of Eratosthenes can be quickly used to determine whether a number is a prime and to find out its prime factorization.

Time complexity

The construction of the sieve takes O(n log log n) time. After this checking whether a number is a prime takes O(1) time and finding the factorization takes O(log n) time.

Implementation details

Internally the sieve stores for each index the largest prime which divides the corresponding value. For 0 and 1 the sieve stores 0 as neither is divisible by any prime.

Implementations

Constructs a new PrimeSieve.

Takes O(n log log n) time.

Checks whether the given number is a prime.

Factorizes the given number into its prime factors.

Returns the factors as pairs indicating the prime and the number of times its present in the factorization. The factorization is ordered in increasing order by the prime.

Turns the sieve into raw vector telling the largest prime divisor for each index.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.