org.apache.commons.math3.primes

## Class Primes

• public class Primes
extends Object
Methods related to prime numbers in the range of int:
• primality test
• prime number generation
• factorization
Since:
3.2
Version:
$Id: Primes.html 908881 2014-05-15 07:10:28Z luc$
• ### Method Detail

• #### isPrime

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 - number to test.
Returns:
true if n is prime. (All numbers < 2 return false).
• #### nextPrime

public static int nextPrime(int n)
Return the smallest prime greater than or equal to n.
Parameters:
n - a positive number.
Returns:
the smallest prime greater than or equal to n.
Throws:
MathIllegalArgumentException - if n < 0.