java.lang.Object de.luschny.math.primes.PrimeSieve
public class PrimeSieve
Sieve.
| Nested Class Summary | |
|---|---|
private
static class |
PrimeSieve.PrimeCollection PrimeCollection. |
| Field Summary | |
|---|---|
(package
private)
PositiveRange |
primeRange
|
(package
private) int[] |
primes
|
(package
private)
PositiveRange |
sieveRange
|
| Constructor Summary | |
|---|---|
PrimeSieve(int
n) Constructs a prime sieve for the integer range [1,n]. |
|
| Method Summary | |
|---|---|
IPrimeCollection |
getCollection()
The default collection of the full sieve. |
IPrimeCollection |
getCollection(int
low, int high) Gives the collection of the prime numbers in the given interval. |
IPrimeCollection |
getCollection(PositiveRange
range) Gives the collection of the prime numbers in the given range. |
int |
getNthPrime(int
n) Get the n-th prime number. |
private
static int |
getPiHighBound(long
n) Get a high bound for pi(n), the number of primes less or equal n. |
de.luschny.math.arithmetic.Xint |
getPrimorial(int
low, int high) Gives the product of the prime numbers in the given interval. |
de.luschny.math.arithmetic.Xint |
getPrimorial(PositiveRange
range) Gives the product of the prime numbers in the given range. |
boolean |
isPrime(int
cand) Checks if a given number is prime. |
private
int |
makePrimeList(int
n) Transforms the sieve of Eratosthenes into the sequence of prime numbers. |
private
static void |
sieveOfEratosthenes(boolean[]
composite) Prime number sieve, Eratosthenes (276-194 b. t.) |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll,
toString, wait, wait, wait |
| Field Detail |
|---|
PositiveRange primeRange
int[] primes
PositiveRange sieveRange
| Constructor Detail |
|---|
public PrimeSieve(int n)
n - The upper bound of the range to be sieved.| Method Detail |
|---|
public IPrimeCollection getCollection()
getCollection
in interface
IPrimeSieve
public IPrimeCollection getCollection(int low,
int high)
getCollection
in interface
IPrimeSievelow - Lower bound of the collection.high - Upper bound of the collection. public IPrimeCollection getCollection(PositiveRange range)
getCollection in interface
IPrimeSieverange - The range of the collection. public int getNthPrime(int n)
getNthPrime
in interface
IPrimeSieven - The index of the prime number. private static int getPiHighBound(long n)
n - Bound of the primes.
public de.luschny.math.arithmetic.Xint getPrimorial(int low,
int high)
low - Lower bound of the collection.high - Upper bound of the collection. public de.luschny.math.arithmetic.Xint getPrimorial(PositiveRange range)
range - The range of the collection. public boolean isPrime(int cand)
isPrime in
interface
IPrimeSievecand - The number to be checked. private int makePrimeList(int n)
n - Upper bound of the sieve. private static void sieveOfEratosthenes(boolean[] composite)
composite - After execution of the function this boolean
array includes all composite numbers in [5,n] disregarding multiples of
2 and 3.