Class SmallPrimes
java.lang.Object
org.apache.commons.math3.primes.SmallPrimes
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int[]The first 512 prime numbers.static final intThe last number in PRIMES. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intboundedTrialDivision(int n, int maxFactor, List<Integer> factors) Extract factors in the rangePRIME_LAST+2tomaxFactors.static booleanmillerRabinPrimeTest(int n) Miller-Rabin probabilistic primality test for int type, used in such a way that a result is always guaranteed.static intsmallTrialDivision(int n, List<Integer> factors) Extract small factors.trialDivision(int n) Factorization by trial division.
-
Field Details
-
PRIMES
public static final int[] PRIMESThe first 512 prime numbers.It contains all primes smaller or equal to the cubic square of Integer.MAX_VALUE. As a result,
intnumbers which are not reduced by those primes are guaranteed to be either prime or semi prime. -
PRIMES_LAST
public static final int PRIMES_LASTThe last number in PRIMES.
-
-
Constructor Details
-
SmallPrimes
private SmallPrimes()Hide utility class.
-
-
Method Details
-
smallTrialDivision
-
boundedTrialDivision
Extract factors in the rangePRIME_LAST+2tomaxFactors.- Parameters:
n- the number to factorize, must be >= PRIME_LAST+2 and must not contain any factor below PRIME_LAST+2maxFactor- the upper bound of trial division: if it is reached, the method gives up and returns n.factors- the list where to add the factors.- Returns:
- n or 1 if factorization is completed.
-
trialDivision
-
millerRabinPrimeTest
public static boolean millerRabinPrimeTest(int n) Miller-Rabin probabilistic primality test for int type, used in such a way that a result is always guaranteed.It uses the prime numbers as successive base therefore it is guaranteed to be always correct. (see Handbook of applied cryptography by Menezes, table 4.1)
- Parameters:
n- number to test: an odd integer ≥ 3- Returns:
- true if n is prime. false if n is definitely composite.
-