https://github.com/scravy/primes4j
Prime numbers up to Integer.MAX_VALUE for Java
https://github.com/scravy/primes4j
java-8 java-library java8 prime-factorizations prime-numbers
Last synced: 8 months ago
JSON representation
Prime numbers up to Integer.MAX_VALUE for Java
- Host: GitHub
- URL: https://github.com/scravy/primes4j
- Owner: scravy
- License: mit
- Created: 2018-05-01T21:15:46.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-23T23:16:06.000Z (over 7 years ago)
- Last Synced: 2025-03-02T09:17:54.035Z (about 1 year ago)
- Topics: java-8, java-library, java8, prime-factorizations, prime-numbers
- Language: Java
- Homepage:
- Size: 11.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# primes4j
This package has a list of all the prime numbers up to `Integer.MAX_VALUE` (2147483647)
which is itself a prime number. This list contains 105097565 entries. The list consists
of a sequence of integers each stored as 4 bytes, thus it is 420390260 bytes in memory.
On top it offers a tiny API to load this list (complete or partially) and for example
find the prime factors for a number or check whether a given `int` is prime or not.
This project is mostly useful for playing around with number theory related problems
which can be computed within the realm of `int` values.
## Maven Coordinates
```
de.scravy
primes4j
2
```
## Usage Example (1)
```
import de.scravy.primes.Primes;
public class Example1 {
public static void main(final String[] args) {
final Primes primes = Primes.load(10000); // only loads 10000 primes which is faster
System.out.println(primes.getPrimeFactors(2868)); // prints [2, 2, 3, 239]
}
}
```
## Usage Example (2)
```
import de.scravy.primes.Primes;
public class Example {
public static void main(final String[] args) {
final Primes primes = Primes.load(); // takes a while as it loads all primes into memory
System.out.println(primes.isPrime(Integer.MAX_VALUE)); // prints true
}
}
```