Top Description Constructors Methods
org.apache.commons.math3.primes

public Class Primes

extends Object
Class Inheritance
Imports
org.apache.commons.math3.exception.MathIllegalArgumentException, org.apache.commons.math3.exception.util.LocalizedFormats, java.util.List

Methods related to prime numbers in the range of int:
Since
3.2

Constructor Summary

AccessConstructor and Description
private
Primes()

Hide utility class.

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if n is prime. (All numbers < 2 return false).
isPrime
(int
number to test.
n
)

Primality test: tells if the argument is a (provable) prime or not.

public static int

Returns:

the smallest prime greater than or equal to n.
nextPrime
(int
a positive number.
n
)

Return the smallest prime greater than or equal to n.

public static List<Integer>

Returns:

list of prime factors of n
primeFactors
(int
number to factorize: must be ≥ 2
n
)

Prime factors decomposition

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Primesback to summary
private Primes()

Hide utility class.

Method Detail

isPrimeback to summary
public static boolean isPrime(int n)

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:int

number to test.

Returns:boolean

true if n is prime. (All numbers < 2 return false).

nextPrimeback to summary
public static int nextPrime(int n)

Return the smallest prime greater than or equal to n.

Parameters
n:int

a positive number.

Returns:int

the smallest prime greater than or equal to n.

Exceptions
MathIllegalArgumentException:
if n < 0.
primeFactorsback to summary
public static List<Integer> primeFactors(int n)

Prime factors decomposition

Parameters
n:int

number to factorize: must be ≥ 2

Returns:List<Integer>

list of prime factors of n

Exceptions
MathIllegalArgumentException:
if n < 2.