Git Product home page Git Product logo

primes4j's Introduction

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

<dependency>
  <groupId>de.scravy</groupId>
  <artifactId>primes4j</artifactId>
  <version>2</version>
</dependency>

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
  }
}

primes4j's People

Contributors

scravy avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.