When you know a thing, to hold that you know it, and when you do not know a thing, to allow that you do not know it - this is knowledge. -Confucius-

Wednesday, December 7, 2016

Segmented Sieve to find primes in a range

There are many approaches to find the primes below a specific number. few better approaches will be Sieve of Eratosthenes and Segmented Sieve (for larger limit). Below are the Java implementation of both. Sieve of Eratosthenes Java Implementation /** * @param limit : The limit can not be large as 1000,000,000 * @return List of primes up to limit, i.e. in the range [0, limit] */ static List< integer > simpleSieve(int limit) { boolean mark[] = new boolean[limit]; Arrays.fill(mark, true); for (int p =...