Class Primes
java.lang.Object
org.apache.commons.numbers.primes.Primes
Methods related to prime numbers in the range of
int.
- primality test
- prime number generation
- factorization
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisPrime(int n) Primality test: tells if the argument is a (provable) prime or not.static intnextPrime(int n) Return the smallest prime greater than or equal to n.primeFactors(int n) Prime factors decomposition.
-
Method Details
-
isPrime
Primality test: tells if the argument is a (provable) prime or not.It uses the Miller-Rabin probabilistic test in such a way that a result is guaranteed: it uses the firsts prime numbers as successive base (see Handbook of applied cryptography by Menezes, table 4.1).
- Parameters:
n- Number to test.- Returns:
- true if
nis prime. All numbers < 2 return false.
-
nextPrime
Return the smallest prime greater than or equal to n.- Parameters:
n- Positive number.- Returns:
- the smallest prime greater than or equal to
n. - Throws:
IllegalArgumentException- if n < 0.
-
primeFactors
Prime factors decomposition.- Parameters:
n- Number to factorize: must be ≥ 2.- Returns:
- the list of prime factors of
n. - Throws:
IllegalArgumentException- if n < 2.
-