13
votes
10answers
1k views

Prime number generator exercise

I have been trying to create a class that would list prime numbers forever. I know it has already been done but I think I learned some valuable principles during my trials. This project helped me ...
11
votes
4answers
276 views

Factorizing integers

I'm working on this method in Java, which is giving me the factors of a number. I'll be using this method a lot, and I was wondering if there isn't a better way of doing it. Like, with just one loop. ...
11
votes
4answers
406 views

Suggestions for improvement on Project Euler #7

Here is a solution for Project Euler Problem #7. By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10,001st prime number? I've ...
10
votes
4answers
280 views

Sieve of Eratosthenes optimization

I am making a program to find primes between the given range of numbers. Unfortunately, the algorithm I created is too slow. Do you have any ideas of how to optimize the code? ...
10
votes
2answers
161 views

Thread-safe prime number source

I am working on some multi-threaded code that requires a prime-number source. The following code keeps an array of primes in memory, extending it as needed. It works in the 'int' domain, being ...
10
votes
3answers
207 views

Project Euler “Largest prime factor” (#3) in Java

The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? I wrote the following code with help of some Java 8, I'll explain the equivalent ...
8
votes
6answers
5k views

Yet another prime number generator

The question asked to find all the prime numbers within a particular range. The way I approached this was to loop through each of the numbers within the range and for each number check whether it's a ...
8
votes
6answers
4k views

Sieve of Eratosthenes

For practice, I've implemented Sieve of Eratosthenes in Java by thinking about this visual animation. I would like to hear some suggestions for improvements, especially how to make it more efficient ...
8
votes
5answers
474 views

Prime Number Sieving Algorithm

Edit: Newly Updated Code here A Fast Approach to Prime Sieving (Array Implementation - Non-Threaded) Original Thread Last semester in my Masters Program I developed this code for sieving. Is this ...
7
votes
7answers
2k views

Sum of the digits is prime or not

Puzzle Description: A number is called lucky if the sum of its digits, as well as the sum of the squares of its digits is a prime number. How many numbers between A and B are lucky? How can ...
7
votes
5answers
484 views

Ten thousand and first prime checker takes a very long time

I am attempting problem 7 on Project Euler. I have come up with this solution which works fine for finding smaller nth prime numbers, but really lags when it comes to higher nth prime numbers. I am ...
7
votes
3answers
264 views

Sieve of Eratosthenes in Java

Here you can find my implementation of sieve of Eratosthenes in Java. ...
6
votes
4answers
287 views

A Fast Approach to Prime Number Sieving (Non-Threaded Array)

I am posting this question for input on comparisons between other sieving methods and opinions on what I have discovered. I believe this might be the fastest (singular, non-threaded) array ...
6
votes
1answer
272 views

Is this the most efficient way to see if the number is prime?

my question is in the title really...is this the most efficiant way to find if a number is prime? ...
5
votes
6answers
310 views

Speeding up my implementation of Project Euler #3

Project Euler problem 3 asks for the largest prime factor of 600851475143. I have gone from 96 lines to 17 lines taking hits at this one. This is what I am left with after all of that effort: ...
5
votes
3answers
77 views

Calculating the ranks of classmates' exam grades

The questions from hackerearth: Geeko is in worry now because an exam is coming up and he has to know what rank he can get on exams. So he goes back into the the school records and finds the ...
4
votes
2answers
172 views

Submitting a Java program which implements the Sieve of Eratosthenes

I would like some feedback on a Java program which implements the Sieve of Eratosthenes to find prime numbers. Some of the 'features' I've included in the program include: It uses a ...
4
votes
3answers
229 views

Prints out all ways to multiply smaller integers that equal the original number

Write a program in Java that takes a positive integer and prints out all ways to multiply smaller integers that equal the original number, without repeating sets of factors. In other words, if ...
4
votes
3answers
111 views

Prime number util class

A prime number util, which provides 3 APIs - find the nth prime, find the next prime, and find all primes up to n. I must admit this code has been influenced a lot by discussions here. I'm ...
4
votes
2answers
155 views
3
votes
2answers
312 views

BigInteger prime testing

...
3
votes
3answers
536 views

Smallest prime factor of a large number (using BigInteger)

I'm working on a Project Euler problem and am trying to get the smallest prime factor of a BigInteger: ...
3
votes
1answer
172 views

Sum of two squares

I'm trying to do a SPOJ problem called twosquares where you check whether the current number can be obtained by adding two squares together. However, I'm getting a "time limit exceeded" message. I'm ...
3
votes
3answers
537 views

Determining whether or not a number is prime

I wrote this code in Java without using any methods, just by using simple for loop and if statements. When we input a number, ...
3
votes
2answers
863 views

Random Prime generator

I have this method that will give a random prime for a given range (min inclusive an max not inclusive) all comments are welcome: ...
3
votes
1answer
124 views

Sierpinski gasket - patterns from primes

Below is the code I have written. I started yesterday with prime numbers and playing around with them. What the code does it determines the "prime gap" between primes numbers, prints them, then finds ...
2
votes
5answers
592 views

Miller-Rabin Prime test (Speed is the main goal)

The code below is for testing Primes. testPrime(100000); testPrime(1000000); testPrime(10000000); testPrime(100000000); Now my goal is to make the code super ...
2
votes
2answers
694 views

Find next consecutive prime and find nth prime

Code review for best practices, optimizations, bug detection etc. Also please verify my complexity as mentioned within the function comments. ...
2
votes
3answers
504 views

Project Euler Problem #3 - largest prime factor

I have began doing the problems found on Project Euler and have just solved problem 3. However, I feel as if my code is very long and too brute-force. I was hoping somebody could give it a look and ...
1
vote
4answers
634 views
1
vote
4answers
3k views

Need a faster way to determine largest prime factor

Project Euler problem 3 asks: What is the largest prime factor of the number 600851475143? The first step I took is to determine the highest value number I should be looking at as a possibility ...
1
vote
3answers
216 views

Primes Tester for speed performance

I was given a homework assignment in Java to create classes that find Prime number and etc (you will see in code better). ...
0
votes
1answer
164 views

Sphere Online Judge, Problem 2: Prime Number Generator

I am trying to solve this problem on Sphere Online Judge. I keep getting a timeout error. Any comments or suggestions are welcome and appreciated. ...
-1
votes
1answer
195 views

How to apply Sieve of Eratosthenes test into my code [closed]

I have this code that tests prime numbers and I'm trying to make it fast as possible. I know a way but I just can't find how to execute it in to my code. Does any one know how to input in to the code ...