Class Primes
java.lang.Object
org.episteme.core.mathematics.numbertheory.Primes
Prime number utilities including generation, testing, and factorization.
Implements classical number theory algorithms including the Sieve of Eratosthenes and the Miller-Rabin probabilistic primality test.
References
- Eratosthenes of Cyrene, Sieve of Eratosthenes, circa 240 BCE (ancient algorithm)
- Gary L. Miller, "Riemann's Hypothesis and Tests for Primality", Journal of Computer and System Sciences, Vol. 13, No. 3, 1976, pp. 300-317
- Michael O. Rabin, "Probabilistic Algorithm for Testing Primality", Journal of Number Theory, Vol. 12, No. 1, 1980, pp. 128-138
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Map<BigInteger, Integer> Computes prime factorization of n.static BigIntegergcd(BigInteger a, BigInteger b) Computes the greatest common divisor using Euclid's algorithm.static booleanTests if a number is prime.static BigIntegerlcm(BigInteger a, BigInteger b) Computes the least common multiple.static BigIntegerReturns the next prime after n.sieveOfEratosthenes(int n) Generates primes up to n using Sieve of Eratosthenes.
-
Constructor Details
-
Primes
public Primes()
-
-
Method Details
-
isPrime
Tests if a number is prime.Uses trial division for small numbers and Miller-Rabin probabilistic test for large numbers (with high certainty).
- Parameters:
n- the number to test- Returns:
- true if probably prime
-
sieveOfEratosthenes
-
factorize
Computes prime factorization of n.- Parameters:
n- number to factorize- Returns:
- map of prime factors to their exponents
-
nextPrime
Returns the next prime after n.- Parameters:
n- starting number- Returns:
- next prime number
-
gcd
Computes the greatest common divisor using Euclid's algorithm.- Parameters:
a- first numberb- second number- Returns:
- gcd(a, b)
-
lcm
Computes the least common multiple.- Parameters:
a- first numberb- second number- Returns:
- lcm(a, b)
-