Class PrimeList
java.lang.Object
edu.jas.arith.PrimeList
- All Implemented Interfaces:
Iterable<BigInteger>
List of big primes. Provides an Iterator for generating prime numbers.
Similar to ALDES/SAC2 SACPOL.PRIME list.
See Knuth vol 2, page 390, for list of known primes. See also ALDES/SAC2
SACPOL.PRIME
- Author:
- Heinz Kredel
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for PrimeList.Constructor for PrimeList. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanCheck if the list contains really prime numbers.protected booleancheckPrimes(int n) Check if the list contains really prime numbers.get(int i) Get prime at index i.static BigIntegergetLongPrime(int n, int m) Method to compute a prime as 2**n - m.static BigIntegergetMersennePrime(int n) Method to compute a Mersenne prime as 2**n - 1.iterator()Iterator.intsize()Size of current list.toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
PrimeList
public PrimeList()Constructor for PrimeList. -
PrimeList
Constructor for PrimeList.- Parameters:
r- size range for primes.
-
-
Method Details
-
getLongPrime
Method to compute a prime as 2**n - m.- Parameters:
n- power for 2.m- for 2**n - m.- Returns:
- 2**n - m
-
getMersennePrime
Method to compute a Mersenne prime as 2**n - 1.- Parameters:
n- power for 2.- Returns:
- 2**n - 1
-
checkPrimes
protected boolean checkPrimes()Check if the list contains really prime numbers.- Returns:
- true if all checked numbers are prime
-
checkPrimes
protected boolean checkPrimes(int n) Check if the list contains really prime numbers.- Parameters:
n- number of primes to check.- Returns:
- true if all checked numbers are prime
-
toString
-
size
public int size()Size of current list.- Returns:
- current size of list.
-
get
Get prime at index i.- Parameters:
i- index to get element.- Returns:
- prime at index i.
-
iterator
Iterator. Always has next, will generate new primes if required.- Specified by:
iteratorin interfaceIterable<BigInteger>- Returns:
- iterator over the prime list.
-