All Questions
24 questions
2
votes
1
answer
144
views
What is the most efficient way to figure out if a single number is prime for numbers from 2 up to 2,147,483,647 in Java?
As Java programmers, we can always use the BigInteger isProbablePrime() method or store manually all prime numbers in a HashMap. This question is about the most efficient way to figure out if a single ...
7
votes
2
answers
2k
views
Arranging numbers in a circle such that the sums of neighbors and sums of diametric opposites are prime
I need to create a circle with numbers from 1 to n , however it is necessary to respect some rules:
All numbers from 1 to n are used in the circle only once.
The sum of two consecutive numbers ...
6
votes
2
answers
264
views
Goldbach conjecture solution finder
The Goldbach conjecture says: any even number greater than two can be represented by the sum of two prime numbers.
G(n) = { (p1, p2) | p1 + p2 = n, p1 and p2 are prime numbers with p1 < p2 }
For ...
3
votes
1
answer
1k
views
Sieve of Eratosthenes using Java 8 streams
I am learning streams and lambdas in Java 8.
I wanted to implement the classic Sieve of Eratosthenes using lambdas and streams. This is my implementation.
...
2
votes
2
answers
923
views
Space and time efficient Algorithm for generating prime numbers
I have developed an algorithm for generating prime numbers (which turns out to be an optimized version of the Sieve of Eratosthenes) by reducing the space by a factor of 64.
...
4
votes
1
answer
411
views
TLE on SPOJ for Prime Generator (PRIME1)
The objective is to find all primes between two given numbers. It is specified that the two numbers are \$\le\$ 1 billion and the difference between the two numbers is ~100,000. We are to repeat the ...
4
votes
3
answers
13k
views
Finding prime numbers in user specified array
I have a program that searches for prime numbers in an array specified by the user. The program starts by asking how big the user wants the array to be, then asks how many threads to split the ...
4
votes
1
answer
272
views
Windowed Sieve of Eratosthenes in Java
I wanted to try and use the Sieve of Eratosthenes to find all prime numbers between some arbitrary bounds 1 <= m <= n. The simple implementation of the sieve ...
2
votes
2
answers
345
views
Finding all the prime factors of a number
I want to calculate all the prime factors of a number in the range 2 ≤ N ≤ 107. Here is my function:
...
3
votes
4
answers
334
views
Prime number generation algorithm
I'm making a prime number scanning algorithm in Java. It uses the concept of the Sieve of Eratosthenes to efficiently find the prime numbers.
It works well and can calculate all the prime numbers ...
8
votes
2
answers
3k
views
Sum the exponents of the prime factors of a number
My goal is to find the sum of the exponents of the prime factors of an integer.
I wrote the code below with the complexities specified here (I am not 100% sure of the complexities though):
Runtime ...
0
votes
1
answer
565
views
Speeding up Mersenne prime generator
I am writing a program to calculate Mersenne primes. This code works, but it is so slow:
...
9
votes
6
answers
10k
views
Program for finding Fibonacci primes
I think it could have been designed with more object orientation. I don't like how one of my methods calls another from within the method, but I wasn't sure how to return the result because it is a ...
11
votes
5
answers
3k
views
Prime Number Sieving Algorithm
Last semester in my Masters Program I developed this code for sieving. My professor wants me to write a report that he might use locally within the school, but I feel like I've done nothing that new, ...
2
votes
4
answers
3k
views